mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
Add orFail method
This commit is contained in:
Vendored
+24
@@ -2021,6 +2021,30 @@ declare module "mongoose" {
|
||||
*/
|
||||
or(array: any[]): this;
|
||||
|
||||
/**
|
||||
* Make this query throw an error if no documents match the given `filter`.
|
||||
* This is handy for integrating with async/await, because `orFail()` saves you
|
||||
* an extra `if` statement to check if no document was found.
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* // Throws if no doc returned
|
||||
* await Model.findOne({ foo: 'bar' }).orFail();
|
||||
*
|
||||
* // Throws if no document was updated
|
||||
* await Model.updateOne({ foo: 'bar' }, { name: 'test' }).orFail();
|
||||
*
|
||||
* // Throws "No docs found!" error if no docs match `{ foo: 'bar' }`
|
||||
* await Model.find({ foo: 'bar' }).orFail(new Error('No docs found!'));
|
||||
*
|
||||
* // Throws "Not found" error if no document was found
|
||||
* await Model.findOneAndUpdate({ foo: 'bar' }, { name: 'test' }).
|
||||
* orFail(() => Error('Not found'));
|
||||
*
|
||||
* @param err optional error to throw if no docs match `filter`
|
||||
*/
|
||||
orFail(err?: Error | (() => Error)): this;
|
||||
|
||||
/** Specifies a $polygon condition */
|
||||
polygon(...coordinatePairs: number[][]): this;
|
||||
polygon(path: string, ...coordinatePairs: number[][]): this;
|
||||
|
||||
@@ -1080,6 +1080,7 @@ query.find().where('age').in([20, 21]);
|
||||
query.find().in('age', [20, 21]);
|
||||
query.nor([{ color: 'green' }, { status: 'ok' }]).nor([]);
|
||||
query.or([{ color: 'red' }, { status: 'emergency' }]).or([]);
|
||||
query.find({ color: 'blue' }).orFail();
|
||||
query.where('loc').within().polygon([10,20], [13, 25], [7,15]);
|
||||
query.polygon('loc', [10,20], [13, 25], [7,15]);
|
||||
query.findOne().populate('owner').exec(function (err, kitten) {
|
||||
|
||||
Reference in New Issue
Block a user