Giter Club home page Giter Club logo

mongoose-find-or-throw-plugin's Introduction

mongoose-throw-if-not-found-plugin

NPM link

Build Status Coverage Status Greenkeeper badge Supports Node >= 6

Don't check for nulls when running your Mongoose 5 queries - let rejected promises do it for you.

Before:

MyModel.findOne({foo: 'bar'})
  .then(doc => {
    if (!doc) {
      throw new Error('Doc not found');
    }
    
    useDoc(doc);
  });

After:

MyModel.findOne({foo: 'bar'})
  .throwIfEmpty()
  .then(doc => {
    useDoc(doc);
  })
  .catch(e => {
    console.log(e.status); // 404
    console.log(e.message); // Not found
    console.log(e.name); // MongooseDocumentNotFoundError
  })

Usage

Simply import the library once anywhere in your code:

require('mongoose-throw-if-not-found-plugin');

It'll handle itself from there ;)

TypeScript usage

While typings are provided, sometimes your IDE may fail to recognise them for code hints. If this happens, simply add the import to the file you're using it from:

import 'mongoose-throw-if-not-found-plugin';

mongoose-find-or-throw-plugin's People

Contributors

alorel avatar greenkeeper[bot] avatar

Watchers

 avatar  avatar  avatar

mongoose-find-or-throw-plugin's Issues

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of mongoose is breaking the build 🚨

Version 5.2.5 of mongoose was just published.

Branch Build failing 🚨
Dependency mongoose
Current Version 5.2.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

mongoose is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 30 commits.

  • 04d5c03 chore: release 5.2.5
  • 9a53a2d Merge branch 'master' of github.com:Automattic/mongoose
  • 559ae4e docs(connections): add note about the family option for IPv4 vs IPv6 and add port to example URIs
  • 66a504a Merge pull request #6744 from lineus/docs-6742
  • 95e553f docs(schematypes): add note about what values are converted to booleans
  • a37fd2f fix(boolean): expose convertToTrue and convertToFalse for custom boolean casting
  • 0ff9359 test(document): repro #6758
  • 4a548af perf(model): create error rather than modifying stack for source map perf
  • ebec9d4 fix(document): fix(document): report castError when setting single nested doc to array
  • ce3e00b test(document): repro #6753
  • 58c51ba Merge pull request #6751 from sajadtorkamani/patch-1
  • e32f721 Prefix mongoose.Schema call with new operator
  • 971311e docs(query): add examples and links to schema writeConcern option for writeConcern helpers
  • 4514037 changed space to -
  • a06cda2 Merge branch 'master' of github.com:Automattic/mongoose

There are 30 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of mongoose is breaking the build 🚨

Version 5.2.1 of mongoose was just published.

Branch Build failing 🚨
Dependency mongoose
Current Version 5.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

mongoose is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 7 commits.

  • f7f55b0 chore: release 5.2.1
  • ff08b9c fix(model): only warn on custom _id index if index only has _id key
  • 2decc5b fix(connection): allow setting the mongodb driver's useNewUrlParser option, default to false
  • b2c1c6d chore: now working on 5.2.1
  • d90ef00 Merge pull request #6652 from lineus/temp-fix-conn-issues
  • a016a2f docs(model): add session to startSession() example
  • 727eda4 dont use newUrlParser until next driver update

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of mongoose is breaking the build 🚨

Version 5.2.0 of mongoose was just published.

Branch Build failing 🚨
Dependency mongoose
Current Version 5.1.8
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

mongoose is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 41 commits.

  • d457cbe chore: release 5.2.0
  • 5d730d4 Merge pull request #6600 from Automattic/5.2
  • 985a845 feat(model): make ensureIndexes() fail if specifying an index on _id
  • 93d06a4 feat(model): add countDocuments()
  • cb2a9a8 Merge branch 'master' into 5.2
  • 44928ef test: fix tests
  • dd3ee74 fix(model): ignore sparse indexes when using decorateDiscriminatorIndexOptions()
  • 8d775f1 feat(model): decorate unique discriminator indexes with partialFilterExpressions
  • 678692e test(model): repro #6347
  • b5f928d chore: add missing strict mode
  • 7839a0d feat(discriminator): support discriminators on nested doc arrays
  • 91980e4 feat(model): add syncIndexes(), drops indexes that aren't in schema
  • e6a30b9 chore: depend on mongodb-core for require() with node v4
  • f39595e feat(model): add listIndexes() helper
  • 0a2d255 fix: avoid using Object.values() for old node versions

There are 41 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of mongoose is breaking the build 🚨

Version 5.2.9 of mongoose was just published.

Branch Build failing 🚨
Dependency mongoose
Current Version 5.2.8
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

mongoose is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).
  • coverage/coveralls: First build on greenkeeper/mongoose-5.2.9 at 100.0% (Details).

Commits

The new version differs by 43 commits.

  • 7875d53 Merge branch 'master' of github.com:Automattic/mongoose
  • 3a8d8cf chore: release 5.2.9
  • 9eb4dc6 chore: add cpc ads to more guides
  • 942a54d Merge pull request #6877 from Fonger/patch-write-concern
  • 4abdf8e chore: fix typo
  • fb447d0 fix(model): correctly propagate writeConcern options in save()
  • e7b6f0d test(model): repro #6862
  • 7e8e7f0 Merge pull request #6866 from Fonger/buffer-json-cast
  • c7e291f Merge pull request #6868 from Fonger/gh-6840-fix
  • dcbd790 test(connection): increase delay in reconnectFailed test
  • 068f584 docs(faq): add question about localhost being slow if no IPv6
  • 25196b2 Merge pull request #6869 from simllll/patch-4
  • d907dc2 test: work around mongodb/node-mongodb-native#1812
  • 0b5803b fix(query): get global runValidators option correctly
  • 24d1f6b test(mongoose): repro #6578

There are 43 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.