mongoose 6.2.9 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/browser.umd.js +2 -1693
- package/lib/aggregate.js +59 -67
- package/lib/browser.js +4 -4
- package/lib/connection.js +21 -21
- package/lib/cursor/AggregationCursor.js +2 -2
- package/lib/cursor/ChangeStream.js +42 -2
- package/lib/cursor/QueryCursor.js +5 -3
- package/lib/document.js +39 -46
- package/lib/error/eachAsyncMultiError.js +41 -0
- package/lib/error/index.js +2 -2
- package/lib/helpers/cursor/eachAsync.js +44 -12
- package/lib/helpers/indexes/applySchemaCollation.js +13 -0
- package/lib/helpers/indexes/isTextIndex.js +16 -0
- package/lib/helpers/model/discriminator.js +1 -3
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/query/applyGlobalOption.js +29 -0
- package/lib/helpers/query/castUpdate.js +3 -1
- package/lib/helpers/update/applyTimestampsToChildren.js +2 -2
- package/lib/helpers/update/applyTimestampsToUpdate.js +0 -1
- package/lib/index.js +33 -26
- package/lib/model.js +88 -90
- package/lib/options/SchemaArrayOptions.js +2 -2
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDateOptions.js +2 -2
- package/lib/options/SchemaDocumentArrayOptions.js +3 -3
- package/lib/options/SchemaMapOptions.js +2 -2
- package/lib/options/SchemaNumberOptions.js +3 -3
- package/lib/options/SchemaObjectIdOptions.js +2 -2
- package/lib/options/SchemaStringOptions.js +1 -1
- package/lib/options/SchemaSubdocumentOptions.js +2 -2
- package/lib/options/SchemaTypeOptions.js +3 -3
- package/lib/query.js +273 -249
- package/lib/schema/SubdocumentPath.js +4 -3
- package/lib/schema/array.js +2 -2
- package/lib/schema/boolean.js +4 -4
- package/lib/schema/buffer.js +3 -3
- package/lib/schema/date.js +7 -7
- package/lib/schema/decimal128.js +2 -2
- package/lib/schema/documentarray.js +3 -3
- package/lib/schema/mixed.js +2 -2
- package/lib/schema/number.js +6 -6
- package/lib/schema/objectid.js +4 -7
- package/lib/schema/string.js +38 -16
- package/lib/schema.js +144 -30
- package/lib/schematype.js +75 -68
- package/lib/types/ArraySubdocument.js +1 -1
- package/lib/types/DocumentArray/methods/index.js +2 -2
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +13 -13
- package/lib/types/buffer.js +1 -1
- package/lib/types/decimal128.js +1 -1
- package/lib/types/objectid.js +1 -1
- package/lib/types/subdocument.js +31 -2
- package/lib/validoptions.js +1 -0
- package/lib/virtualtype.js +3 -3
- package/package.json +19 -13
- package/tools/repl.js +2 -1
- package/types/aggregate.d.ts +223 -0
- package/types/cursor.d.ts +10 -4
- package/types/index.d.ts +194 -209
- package/types/mongooseoptions.d.ts +10 -4
- package/lib/helpers/query/applyGlobalMaxTimeMS.js +0 -15
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference path="./aggregate.d.ts" />
|
|
1
2
|
/// <reference path="./connection.d.ts" />
|
|
2
3
|
/// <reference path="./cursor.d.ts" />
|
|
3
4
|
/// <reference path="./document.d.ts" />
|
|
@@ -248,7 +249,11 @@ declare module 'mongoose' {
|
|
|
248
249
|
|
|
249
250
|
interface ModifyResult<T> {
|
|
250
251
|
value: Require_id<T> | null;
|
|
251
|
-
|
|
252
|
+
/** see https://www.mongodb.com/docs/manual/reference/command/findAndModify/#lasterrorobject */
|
|
253
|
+
lastErrorObject?: {
|
|
254
|
+
updatedExisting?: boolean;
|
|
255
|
+
upserted?: mongodb.ObjectId;
|
|
256
|
+
};
|
|
252
257
|
ok: 0 | 1;
|
|
253
258
|
}
|
|
254
259
|
|
|
@@ -294,7 +299,7 @@ declare module 'mongoose' {
|
|
|
294
299
|
|
|
295
300
|
/** Creates a `countDocuments` query: counts the number of documents that match `filter`. */
|
|
296
301
|
countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
297
|
-
countDocuments(filter: FilterQuery<T>, options?: QueryOptions
|
|
302
|
+
countDocuments(filter: FilterQuery<T>, options?: QueryOptions<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
298
303
|
|
|
299
304
|
/** Creates a new document or documents */
|
|
300
305
|
create(docs: (AnyKeys<T> | AnyObject)[], options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
@@ -330,7 +335,7 @@ declare module 'mongoose' {
|
|
|
330
335
|
* Behaves like `remove()`, but deletes all documents that match `conditions`
|
|
331
336
|
* regardless of the `single` option.
|
|
332
337
|
*/
|
|
333
|
-
deleteMany(filter?: FilterQuery<T>, options?: QueryOptions
|
|
338
|
+
deleteMany(filter?: FilterQuery<T>, options?: QueryOptions<T>, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
334
339
|
deleteMany(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
335
340
|
deleteMany(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
336
341
|
|
|
@@ -339,7 +344,7 @@ declare module 'mongoose' {
|
|
|
339
344
|
* Behaves like `remove()`, but deletes at most one document regardless of the
|
|
340
345
|
* `single` option.
|
|
341
346
|
*/
|
|
342
|
-
deleteOne(filter?: FilterQuery<T>, options?: QueryOptions
|
|
347
|
+
deleteOne(filter?: FilterQuery<T>, options?: QueryOptions<T>, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
343
348
|
deleteOne(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
344
349
|
deleteOne(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
345
350
|
|
|
@@ -361,10 +366,34 @@ declare module 'mongoose' {
|
|
|
361
366
|
* equivalent to `findOne({ _id: id })`. If you want to query by a document's
|
|
362
367
|
* `_id`, use `findById()` instead of `findOne()`.
|
|
363
368
|
*/
|
|
364
|
-
findById<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
369
|
+
findById<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
370
|
+
id: any,
|
|
371
|
+
projection?: ProjectionType<T> | null,
|
|
372
|
+
options?: QueryOptions<T> | null,
|
|
373
|
+
callback?: Callback<ResultDoc | null>
|
|
374
|
+
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
375
|
+
findById<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
376
|
+
id: any,
|
|
377
|
+
projection?: ProjectionType<T> | null,
|
|
378
|
+
callback?: Callback<ResultDoc | null>
|
|
379
|
+
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
365
380
|
|
|
366
381
|
/** Finds one document. */
|
|
367
|
-
findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
382
|
+
findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
383
|
+
filter?: FilterQuery<T>,
|
|
384
|
+
projection?: ProjectionType<T> | null,
|
|
385
|
+
options?: QueryOptions<T> | null,
|
|
386
|
+
callback?: Callback<ResultDoc | null>
|
|
387
|
+
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
388
|
+
findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
389
|
+
filter?: FilterQuery<T>,
|
|
390
|
+
projection?: ProjectionType<T> | null,
|
|
391
|
+
callback?: Callback<ResultDoc | null>
|
|
392
|
+
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
393
|
+
findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
394
|
+
filter?: FilterQuery<T>,
|
|
395
|
+
callback?: Callback<ResultDoc | null>
|
|
396
|
+
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
368
397
|
|
|
369
398
|
/**
|
|
370
399
|
* Shortcut for creating a new Document from existing raw data, pre-saved in the DB.
|
|
@@ -453,7 +482,7 @@ declare module 'mongoose' {
|
|
|
453
482
|
distinct<ReturnType = any>(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
454
483
|
|
|
455
484
|
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
|
|
456
|
-
estimatedDocumentCount(options?: QueryOptions
|
|
485
|
+
estimatedDocumentCount(options?: QueryOptions<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
457
486
|
|
|
458
487
|
/**
|
|
459
488
|
* Returns a document with its `_id` if at least one document exists in the database that matches
|
|
@@ -464,37 +493,61 @@ declare module 'mongoose' {
|
|
|
464
493
|
|
|
465
494
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
466
495
|
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
496
|
+
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
497
|
+
filter: FilterQuery<T>,
|
|
498
|
+
projection?: ProjectionType<T> | null,
|
|
499
|
+
callback?: Callback<ResultDoc[]>
|
|
500
|
+
): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
467
501
|
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
468
|
-
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, projection?:
|
|
502
|
+
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, projection?: ProjectionType<T> | null, options?: QueryOptions<T> | null, callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
469
503
|
|
|
470
504
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
471
|
-
findByIdAndDelete<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
505
|
+
findByIdAndDelete<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
472
506
|
|
|
473
507
|
/** Creates a `findByIdAndRemove` query, filtering by the given `_id`. */
|
|
474
|
-
findByIdAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
508
|
+
findByIdAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
475
509
|
|
|
476
510
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
477
|
-
findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
478
|
-
findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
|
|
479
|
-
findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
511
|
+
findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions<T> & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
512
|
+
findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions<T> & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
|
|
513
|
+
findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, update?: UpdateQuery<T>, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
480
514
|
findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, callback: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
481
515
|
|
|
482
516
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
483
|
-
findOneAndDelete<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
517
|
+
findOneAndDelete<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
484
518
|
|
|
485
519
|
/** Creates a `findOneAndRemove` query: atomically finds the given document and deletes it. */
|
|
486
|
-
findOneAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
520
|
+
findOneAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
487
521
|
|
|
488
522
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
489
|
-
findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
|
|
490
|
-
findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
523
|
+
findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions<T> & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
|
|
524
|
+
findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
491
525
|
|
|
492
526
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
493
|
-
findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
527
|
+
findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
528
|
+
filter: FilterQuery<T>,
|
|
529
|
+
update: UpdateQuery<T>,
|
|
530
|
+
options: QueryOptions<T> & { rawResult: true },
|
|
531
|
+
callback?: (err: CallbackError, doc: any, res: any) => void
|
|
532
|
+
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
533
|
+
findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
534
|
+
filter: FilterQuery<T>,
|
|
535
|
+
update: UpdateQuery<T>,
|
|
536
|
+
options: QueryOptions<T> & { upsert: true } & ReturnsNewDoc,
|
|
537
|
+
callback?: (err: CallbackError, doc: ResultDoc, res: any) => void
|
|
538
|
+
): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
|
|
539
|
+
findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
540
|
+
filter?: FilterQuery<T>,
|
|
541
|
+
update?: UpdateQuery<T>,
|
|
542
|
+
options?: QueryOptions<T> | null,
|
|
543
|
+
callback?: (err: CallbackError, doc: T | null, res: any) => void
|
|
544
|
+
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
|
|
545
|
+
|
|
546
|
+
geoSearch<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
547
|
+
filter?: FilterQuery<T>,
|
|
548
|
+
options?: GeoSearchOptions,
|
|
549
|
+
callback?: Callback<Array<ResultDoc>>
|
|
550
|
+
): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
498
551
|
|
|
499
552
|
/** Executes a mapReduce command. */
|
|
500
553
|
mapReduce<Key, Value>(
|
|
@@ -505,8 +558,18 @@ declare module 'mongoose' {
|
|
|
505
558
|
remove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: any, callback?: CallbackWithoutResult): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
506
559
|
|
|
507
560
|
/** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */
|
|
508
|
-
replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
509
|
-
|
|
561
|
+
replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
562
|
+
filter?: FilterQuery<T>,
|
|
563
|
+
replacement?: T | AnyObject,
|
|
564
|
+
options?: QueryOptions<T> | null,
|
|
565
|
+
callback?: Callback
|
|
566
|
+
): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
567
|
+
replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
568
|
+
filter?: FilterQuery<T>,
|
|
569
|
+
replacement?: T | AnyObject,
|
|
570
|
+
options?: QueryOptions<T> | null,
|
|
571
|
+
callback?: Callback
|
|
572
|
+
): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
510
573
|
|
|
511
574
|
/** Schema the model uses. */
|
|
512
575
|
schema: Schema<T>;
|
|
@@ -515,13 +578,28 @@ declare module 'mongoose' {
|
|
|
515
578
|
* @deprecated use `updateOne` or `updateMany` instead.
|
|
516
579
|
* Creates a `update` query: updates one or many documents that match `filter` with `update`, based on the `multi` option.
|
|
517
580
|
*/
|
|
518
|
-
update<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
581
|
+
update<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
582
|
+
filter?: FilterQuery<T>,
|
|
583
|
+
update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
|
|
584
|
+
options?: QueryOptions<T> | null,
|
|
585
|
+
callback?: Callback
|
|
586
|
+
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
519
587
|
|
|
520
588
|
/** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
|
|
521
|
-
updateMany<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
589
|
+
updateMany<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
590
|
+
filter?: FilterQuery<T>,
|
|
591
|
+
update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
|
|
592
|
+
options?: QueryOptions<T> | null,
|
|
593
|
+
callback?: Callback
|
|
594
|
+
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
522
595
|
|
|
523
596
|
/** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */
|
|
524
|
-
updateOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
597
|
+
updateOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
598
|
+
filter?: FilterQuery<T>,
|
|
599
|
+
update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
|
|
600
|
+
options?: QueryOptions<T> | null,
|
|
601
|
+
callback?: Callback
|
|
602
|
+
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
525
603
|
|
|
526
604
|
/** Creates a Query, applies the passed conditions, and returns the Query. */
|
|
527
605
|
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(path: string, val?: any): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
@@ -531,7 +609,7 @@ declare module 'mongoose' {
|
|
|
531
609
|
|
|
532
610
|
type UpdateWriteOpResult = mongodb.UpdateResult;
|
|
533
611
|
|
|
534
|
-
interface QueryOptions {
|
|
612
|
+
interface QueryOptions<DocType = unknown> {
|
|
535
613
|
arrayFilters?: { [key: string]: any }[];
|
|
536
614
|
batchSize?: number;
|
|
537
615
|
collation?: mongodb.CollationOptions;
|
|
@@ -558,7 +636,7 @@ declare module 'mongoose' {
|
|
|
558
636
|
overwrite?: boolean;
|
|
559
637
|
overwriteDiscriminatorKey?: boolean;
|
|
560
638
|
populate?: string | string[] | PopulateOptions | PopulateOptions[];
|
|
561
|
-
projection?:
|
|
639
|
+
projection?: ProjectionType<DocType>;
|
|
562
640
|
/**
|
|
563
641
|
* if true, returns the raw result from the MongoDB driver
|
|
564
642
|
*/
|
|
@@ -606,7 +684,7 @@ declare module 'mongoose' {
|
|
|
606
684
|
[other: string]: any;
|
|
607
685
|
}
|
|
608
686
|
|
|
609
|
-
type MongooseQueryOptions = Pick<QueryOptions
|
|
687
|
+
type MongooseQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, 'populate' | 'lean' | 'strict' | 'sanitizeProjection' | 'sanitizeFilter'>;
|
|
610
688
|
|
|
611
689
|
interface SaveOptions {
|
|
612
690
|
checkKeys?: boolean;
|
|
@@ -751,8 +829,6 @@ declare module 'mongoose' {
|
|
|
751
829
|
type SchemaPreOptions = { document?: boolean, query?: boolean };
|
|
752
830
|
type SchemaPostOptions = { document?: boolean, query?: boolean };
|
|
753
831
|
|
|
754
|
-
type ExtractVirtuals<M> = M extends Model<any, any, any, infer TVirtuals> ? TVirtuals : {};
|
|
755
|
-
|
|
756
832
|
type IndexDirection = 1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text';
|
|
757
833
|
type IndexDefinition = Record<string, IndexDirection>;
|
|
758
834
|
|
|
@@ -777,6 +853,9 @@ declare module 'mongoose' {
|
|
|
777
853
|
*/
|
|
778
854
|
childSchemas: { schema: Schema, model: any }[];
|
|
779
855
|
|
|
856
|
+
/** Removes all indexes on this schema */
|
|
857
|
+
clearIndexes(): this;
|
|
858
|
+
|
|
780
859
|
/** Returns a copy of this schema */
|
|
781
860
|
clone<T = this>(): T;
|
|
782
861
|
|
|
@@ -876,6 +955,9 @@ declare module 'mongoose' {
|
|
|
876
955
|
/** Removes the given `path` (or [`paths`]). */
|
|
877
956
|
remove(paths: string | Array<string>): this;
|
|
878
957
|
|
|
958
|
+
/** Removes index by name or index spec */
|
|
959
|
+
remove(index: string | AnyObject): this;
|
|
960
|
+
|
|
879
961
|
/** Returns an Array of path strings that are required by this schema. */
|
|
880
962
|
requiredPaths(invalidate?: boolean): string[];
|
|
881
963
|
|
|
@@ -890,7 +972,10 @@ declare module 'mongoose' {
|
|
|
890
972
|
statics: { [name: string]: (this: M, ...args: any[]) => any };
|
|
891
973
|
|
|
892
974
|
/** Creates a virtual type with the given name. */
|
|
893
|
-
virtual<T = HydratedDocument<DocType, TInstanceMethods>>(
|
|
975
|
+
virtual<T = HydratedDocument<DocType, TInstanceMethods>>(
|
|
976
|
+
name: string,
|
|
977
|
+
options?: VirtualTypeOptions<T, DocType>
|
|
978
|
+
): VirtualType;
|
|
894
979
|
|
|
895
980
|
/** Object of currently defined virtuals on this schema */
|
|
896
981
|
virtuals: any;
|
|
@@ -924,7 +1009,8 @@ declare module 'mongoose' {
|
|
|
924
1009
|
Function[] |
|
|
925
1010
|
SchemaDefinition<T> |
|
|
926
1011
|
SchemaDefinition<Unpacked<T>>[] |
|
|
927
|
-
typeof
|
|
1012
|
+
typeof Schema.Types.Mixed |
|
|
1013
|
+
MixedSchemaTypeOptions;
|
|
928
1014
|
|
|
929
1015
|
type SchemaDefinition<T = undefined> = T extends undefined
|
|
930
1016
|
? { [path: string]: SchemaDefinitionProperty; }
|
|
@@ -939,6 +1025,10 @@ declare module 'mongoose' {
|
|
|
939
1025
|
|
|
940
1026
|
type ExtractMongooseArray<T> = T extends Types.Array<any> ? AnyArray<Unpacked<T>> : T;
|
|
941
1027
|
|
|
1028
|
+
class MixedSchemaTypeOptions extends SchemaTypeOptions<Schema.Types.Mixed> {
|
|
1029
|
+
type: typeof Schema.Types.Mixed;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
942
1032
|
export class SchemaTypeOptions<T> {
|
|
943
1033
|
type?:
|
|
944
1034
|
T extends string ? StringSchemaDefinition :
|
|
@@ -976,7 +1066,7 @@ declare module 'mongoose' {
|
|
|
976
1066
|
* The default value for this path. If a function, Mongoose executes the function
|
|
977
1067
|
* and uses the return value as the default.
|
|
978
1068
|
*/
|
|
979
|
-
default?: ExtractMongooseArray<T> | ((this: any, doc: any) => Partial<ExtractMongooseArray<T>>);
|
|
1069
|
+
default?: T extends Schema.Types.Mixed ? ({} | ((this: any, doc: any) => any)) : (ExtractMongooseArray<T> | ((this: any, doc: any) => Partial<ExtractMongooseArray<T>>));
|
|
980
1070
|
|
|
981
1071
|
/**
|
|
982
1072
|
* The model that `populate()` should use if populating this path.
|
|
@@ -1156,7 +1246,7 @@ declare module 'mongoose' {
|
|
|
1156
1246
|
|
|
1157
1247
|
type InferId<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
|
|
1158
1248
|
|
|
1159
|
-
interface VirtualTypeOptions<HydratedDocType = Document> {
|
|
1249
|
+
interface VirtualTypeOptions<HydratedDocType = Document, DocType = unknown> {
|
|
1160
1250
|
/** If `ref` is not nullish, this becomes a populated virtual. */
|
|
1161
1251
|
ref?: string | Function;
|
|
1162
1252
|
|
|
@@ -1200,7 +1290,7 @@ declare module 'mongoose' {
|
|
|
1200
1290
|
perDocumentLimit?: number;
|
|
1201
1291
|
|
|
1202
1292
|
/** Additional options like `limit` and `lean`. */
|
|
1203
|
-
options?: QueryOptions & { match?: AnyObject };
|
|
1293
|
+
options?: QueryOptions<DocType> & { match?: AnyObject };
|
|
1204
1294
|
|
|
1205
1295
|
/** Additional options for plugins */
|
|
1206
1296
|
[extra: string]: any;
|
|
@@ -1480,7 +1570,7 @@ declare module 'mongoose' {
|
|
|
1480
1570
|
type ProjectionFields<DocType> = { [Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any } & Record<string, any>;
|
|
1481
1571
|
|
|
1482
1572
|
class Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {
|
|
1483
|
-
_mongooseOptions: MongooseQueryOptions
|
|
1573
|
+
_mongooseOptions: MongooseQueryOptions<DocType>;
|
|
1484
1574
|
|
|
1485
1575
|
/**
|
|
1486
1576
|
* Returns a wrapper around a [mongodb driver cursor](http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html).
|
|
@@ -1549,20 +1639,24 @@ declare module 'mongoose' {
|
|
|
1549
1639
|
|
|
1550
1640
|
/** Specifies this query as a `countDocuments` query. */
|
|
1551
1641
|
countDocuments(callback?: Callback<number>): QueryWithHelpers<number, DocType, THelpers, RawDocType>;
|
|
1552
|
-
countDocuments(
|
|
1642
|
+
countDocuments(
|
|
1643
|
+
criteria: FilterQuery<DocType>,
|
|
1644
|
+
options?: QueryOptions<DocType>,
|
|
1645
|
+
callback?: Callback<number>
|
|
1646
|
+
): QueryWithHelpers<number, DocType, THelpers, RawDocType>;
|
|
1553
1647
|
|
|
1554
1648
|
/**
|
|
1555
1649
|
* Returns a wrapper around a [mongodb driver cursor](http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html).
|
|
1556
1650
|
* A QueryCursor exposes a Streams3 interface, as well as a `.next()` function.
|
|
1557
1651
|
*/
|
|
1558
|
-
cursor(options?: QueryOptions): Cursor<DocType, QueryOptions
|
|
1652
|
+
cursor(options?: QueryOptions<DocType>): Cursor<DocType, QueryOptions<DocType>>;
|
|
1559
1653
|
|
|
1560
1654
|
/**
|
|
1561
1655
|
* Declare and/or execute this query as a `deleteMany()` operation. Works like
|
|
1562
1656
|
* remove, except it deletes _every_ document that matches `filter` in the
|
|
1563
1657
|
* collection, regardless of the value of `single`.
|
|
1564
1658
|
*/
|
|
1565
|
-
deleteMany(filter?: FilterQuery<DocType>, options?: QueryOptions
|
|
1659
|
+
deleteMany(filter?: FilterQuery<DocType>, options?: QueryOptions<DocType>, callback?: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1566
1660
|
deleteMany(filter: FilterQuery<DocType>, callback: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1567
1661
|
deleteMany(callback: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1568
1662
|
|
|
@@ -1571,7 +1665,7 @@ declare module 'mongoose' {
|
|
|
1571
1665
|
* remove, except it deletes at most one document regardless of the `single`
|
|
1572
1666
|
* option.
|
|
1573
1667
|
*/
|
|
1574
|
-
deleteOne(filter?: FilterQuery<DocType>, options?: QueryOptions
|
|
1668
|
+
deleteOne(filter?: FilterQuery<DocType>, options?: QueryOptions<DocType>, callback?: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1575
1669
|
deleteOne(filter: FilterQuery<DocType>, callback: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1576
1670
|
deleteOne(callback: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1577
1671
|
|
|
@@ -1593,7 +1687,7 @@ declare module 'mongoose' {
|
|
|
1593
1687
|
equals(val: any): this;
|
|
1594
1688
|
|
|
1595
1689
|
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
|
|
1596
|
-
estimatedDocumentCount(options?: QueryOptions
|
|
1690
|
+
estimatedDocumentCount(options?: QueryOptions<DocType>, callback?: Callback<number>): QueryWithHelpers<number, DocType, THelpers, RawDocType>;
|
|
1597
1691
|
|
|
1598
1692
|
/** Specifies a `$exists` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
1599
1693
|
exists(val: boolean): this;
|
|
@@ -1609,45 +1703,80 @@ declare module 'mongoose' {
|
|
|
1609
1703
|
|
|
1610
1704
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
1611
1705
|
find(callback?: Callback<DocType[]>): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType>;
|
|
1612
|
-
find(
|
|
1613
|
-
|
|
1706
|
+
find(
|
|
1707
|
+
filter: FilterQuery<DocType>,
|
|
1708
|
+
callback?: Callback<DocType[]>
|
|
1709
|
+
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType>;
|
|
1710
|
+
find(
|
|
1711
|
+
filter: FilterQuery<DocType>,
|
|
1712
|
+
projection?: ProjectionType<DocType> | null,
|
|
1713
|
+
callback?: Callback<DocType[]>
|
|
1714
|
+
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType>;
|
|
1715
|
+
find(
|
|
1716
|
+
filter: FilterQuery<DocType>,
|
|
1717
|
+
projection?: ProjectionType<DocType> | null,
|
|
1718
|
+
options?: QueryOptions<DocType> | null,
|
|
1719
|
+
callback?: Callback<DocType[]>
|
|
1720
|
+
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType>;
|
|
1614
1721
|
|
|
1615
1722
|
/** Declares the query a findOne operation. When executed, the first found document is passed to the callback. */
|
|
1616
|
-
findOne(
|
|
1723
|
+
findOne(
|
|
1724
|
+
filter?: FilterQuery<DocType>,
|
|
1725
|
+
projection?: ProjectionType<DocType> | null,
|
|
1726
|
+
options?: QueryOptions<DocType> | null,
|
|
1727
|
+
callback?: Callback<DocType | null>
|
|
1728
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1729
|
+
findOne(
|
|
1730
|
+
filter?: FilterQuery<DocType>,
|
|
1731
|
+
projection?: ProjectionType<DocType> | null,
|
|
1732
|
+
callback?: Callback<DocType | null>
|
|
1733
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1734
|
+
findOne(
|
|
1735
|
+
filter?: FilterQuery<DocType>,
|
|
1736
|
+
callback?: Callback<DocType | null>
|
|
1737
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1617
1738
|
|
|
1618
1739
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
1619
|
-
findOneAndDelete(
|
|
1740
|
+
findOneAndDelete(
|
|
1741
|
+
filter?: FilterQuery<DocType>,
|
|
1742
|
+
options?: QueryOptions<DocType> | null,
|
|
1743
|
+
callback?: (err: CallbackError, doc: DocType | null, res: any) => void
|
|
1744
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1620
1745
|
|
|
1621
1746
|
/** Creates a `findOneAndRemove` query: atomically finds the given document and deletes it. */
|
|
1622
|
-
findOneAndRemove(
|
|
1747
|
+
findOneAndRemove(
|
|
1748
|
+
filter?: FilterQuery<DocType>,
|
|
1749
|
+
options?: QueryOptions<DocType> | null,
|
|
1750
|
+
callback?: (err: CallbackError, doc: DocType | null, res: any) => void
|
|
1751
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1623
1752
|
|
|
1624
1753
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
1625
1754
|
findOneAndUpdate(
|
|
1626
1755
|
filter: FilterQuery<DocType>,
|
|
1627
1756
|
update: UpdateQuery<DocType>,
|
|
1628
|
-
options: QueryOptions & { rawResult: true },
|
|
1757
|
+
options: QueryOptions<DocType> & { rawResult: true },
|
|
1629
1758
|
callback?: (err: CallbackError, doc: DocType | null, res: ModifyResult<DocType>) => void
|
|
1630
1759
|
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType>;
|
|
1631
1760
|
findOneAndUpdate(
|
|
1632
1761
|
filter: FilterQuery<DocType>,
|
|
1633
1762
|
update: UpdateQuery<DocType>,
|
|
1634
|
-
options: QueryOptions & { upsert: true } & ReturnsNewDoc,
|
|
1763
|
+
options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc,
|
|
1635
1764
|
callback?: (err: CallbackError, doc: DocType, res: ModifyResult<DocType>) => void
|
|
1636
1765
|
): QueryWithHelpers<DocType, DocType, THelpers, RawDocType>;
|
|
1637
1766
|
findOneAndUpdate(
|
|
1638
1767
|
filter?: FilterQuery<DocType>,
|
|
1639
1768
|
update?: UpdateQuery<DocType>,
|
|
1640
|
-
options?: QueryOptions | null,
|
|
1769
|
+
options?: QueryOptions<DocType> | null,
|
|
1641
1770
|
callback?: (err: CallbackError, doc: DocType | null, res: ModifyResult<DocType>) => void
|
|
1642
1771
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1643
1772
|
|
|
1644
1773
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
1645
|
-
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1774
|
+
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions<DocType> | null, callback?: (err: CallbackError, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1646
1775
|
|
|
1647
1776
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
1648
|
-
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: any, res?: any) => void): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1649
|
-
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: DocType, res?: any) => void): QueryWithHelpers<DocType, DocType, THelpers, RawDocType>;
|
|
1650
|
-
findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (CallbackError: any, doc: DocType | null, res?: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1777
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions<DocType> & { rawResult: true }, callback?: (err: CallbackError, doc: any, res?: any) => void): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1778
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: DocType, res?: any) => void): QueryWithHelpers<DocType, DocType, THelpers, RawDocType>;
|
|
1779
|
+
findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<DocType>, options?: QueryOptions<DocType> | null, callback?: (CallbackError: any, doc: DocType | null, res?: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1651
1780
|
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, callback: (CallbackError: any, doc: DocType | null, res?: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
1652
1781
|
|
|
1653
1782
|
/** Specifies a `$geometry` condition */
|
|
@@ -1664,7 +1793,7 @@ declare module 'mongoose' {
|
|
|
1664
1793
|
getFilter(): FilterQuery<DocType>;
|
|
1665
1794
|
|
|
1666
1795
|
/** Gets query options. */
|
|
1667
|
-
getOptions(): QueryOptions
|
|
1796
|
+
getOptions(): QueryOptions<DocType>;
|
|
1668
1797
|
|
|
1669
1798
|
/** Gets a list of paths to be populated by this query */
|
|
1670
1799
|
getPopulatedPaths(): Array<string>;
|
|
@@ -1806,8 +1935,8 @@ declare module 'mongoose' {
|
|
|
1806
1935
|
* `update()`, except MongoDB will replace the existing document and will
|
|
1807
1936
|
* not accept any [atomic](https://docs.mongodb.com/manual/tutorial/model-data-for-atomic-operations/#pattern) operators (`$set`, etc.)
|
|
1808
1937
|
*/
|
|
1809
|
-
replaceOne(filter?: FilterQuery<DocType>, replacement?: DocType | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1810
|
-
replaceOne(filter?: FilterQuery<DocType>, replacement?: DocType | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1938
|
+
replaceOne(filter?: FilterQuery<DocType>, replacement?: DocType | AnyObject, options?: QueryOptions<DocType> | null, callback?: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1939
|
+
replaceOne(filter?: FilterQuery<DocType>, replacement?: DocType | AnyObject, options?: QueryOptions<DocType> | null, callback?: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
|
|
1811
1940
|
|
|
1812
1941
|
/** Specifies which document fields to include or exclude (also known as the query "projection") */
|
|
1813
1942
|
select(arg: string | any): this;
|
|
@@ -1836,7 +1965,7 @@ declare module 'mongoose' {
|
|
|
1836
1965
|
set(path: string | Record<string, unknown>, value?: any): this;
|
|
1837
1966
|
|
|
1838
1967
|
/** Sets query options. Some options only make sense for certain operations. */
|
|
1839
|
-
setOptions(options: QueryOptions
|
|
1968
|
+
setOptions(options: QueryOptions<DocType>, overwrite?: boolean): this;
|
|
1840
1969
|
|
|
1841
1970
|
/** Sets the query conditions to the provided JSON object. */
|
|
1842
1971
|
setQuery(val: FilterQuery<DocType> | null): void;
|
|
@@ -1876,7 +2005,7 @@ declare module 'mongoose' {
|
|
|
1876
2005
|
toConstructor(): new (...args: any[]) => QueryWithHelpers<ResultType, DocType, THelpers, RawDocType>;
|
|
1877
2006
|
|
|
1878
2007
|
/** Declare and/or execute this query as an update() operation. */
|
|
1879
|
-
update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|
|
2008
|
+
update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|
|
1880
2009
|
|
|
1881
2010
|
/**
|
|
1882
2011
|
* Declare and/or execute this query as an updateMany() operation. Same as
|
|
@@ -1884,13 +2013,13 @@ declare module 'mongoose' {
|
|
|
1884
2013
|
* `filter` (as opposed to just the first one) regardless of the value of
|
|
1885
2014
|
* the `multi` option.
|
|
1886
2015
|
*/
|
|
1887
|
-
updateMany(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|
|
2016
|
+
updateMany(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|
|
1888
2017
|
|
|
1889
2018
|
/**
|
|
1890
2019
|
* Declare and/or execute this query as an updateOne() operation. Same as
|
|
1891
2020
|
* `update()`, except it does not support the `multi` or `overwrite` options.
|
|
1892
2021
|
*/
|
|
1893
|
-
updateOne(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|
|
2022
|
+
updateOne(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|
|
1894
2023
|
|
|
1895
2024
|
/**
|
|
1896
2025
|
* Sets the specified number of `mongod` servers, or tag set of `mongod` servers,
|
|
@@ -1914,6 +2043,9 @@ declare module 'mongoose' {
|
|
|
1914
2043
|
wtimeout(ms: number): this;
|
|
1915
2044
|
}
|
|
1916
2045
|
|
|
2046
|
+
type ProjectionElementType = number | string;
|
|
2047
|
+
export type ProjectionType<T> = { [P in keyof T]?: ProjectionElementType } | AnyObject | string;
|
|
2048
|
+
|
|
1917
2049
|
export type QuerySelector<T> = {
|
|
1918
2050
|
// Comparison
|
|
1919
2051
|
$eq?: T;
|
|
@@ -2120,153 +2252,6 @@ declare module 'mongoose' {
|
|
|
2120
2252
|
T extends Document ? RawDocType :
|
|
2121
2253
|
T;
|
|
2122
2254
|
|
|
2123
|
-
class Aggregate<R> {
|
|
2124
|
-
/**
|
|
2125
|
-
* Returns an asyncIterator for use with [`for/await/of` loops](https://thecodebarbarian.com/getting-started-with-async-iterators-in-node-js
|
|
2126
|
-
* You do not need to call this function explicitly, the JavaScript runtime
|
|
2127
|
-
* will call it for you.
|
|
2128
|
-
*/
|
|
2129
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<Unpacked<R>>;
|
|
2130
|
-
|
|
2131
|
-
/**
|
|
2132
|
-
* Sets an option on this aggregation. This function will be deprecated in a
|
|
2133
|
-
* future release. */
|
|
2134
|
-
addCursorFlag(flag: string, value: boolean): this;
|
|
2135
|
-
|
|
2136
|
-
/**
|
|
2137
|
-
* Appends a new $addFields operator to this aggregate pipeline.
|
|
2138
|
-
* Requires MongoDB v3.4+ to work
|
|
2139
|
-
*/
|
|
2140
|
-
addFields(arg: PipelineStage.AddFields['$addFields']): this;
|
|
2141
|
-
|
|
2142
|
-
/** Sets the allowDiskUse option for the aggregation query (ignored for < 2.6.0) */
|
|
2143
|
-
allowDiskUse(value: boolean): this;
|
|
2144
|
-
|
|
2145
|
-
/** Appends new operators to this aggregate pipeline */
|
|
2146
|
-
append(...args: any[]): this;
|
|
2147
|
-
|
|
2148
|
-
/**
|
|
2149
|
-
* Executes the query returning a `Promise` which will be
|
|
2150
|
-
* resolved with either the doc(s) or rejected with the error.
|
|
2151
|
-
* Like [`.then()`](#query_Query-then), but only takes a rejection handler.
|
|
2152
|
-
*/
|
|
2153
|
-
catch: Promise<R>['catch'];
|
|
2154
|
-
|
|
2155
|
-
/** Adds a collation. */
|
|
2156
|
-
collation(options: mongodb.CollationOptions): this;
|
|
2157
|
-
|
|
2158
|
-
/** Appends a new $count operator to this aggregate pipeline. */
|
|
2159
|
-
count(countName: PipelineStage.Count['$count']): this;
|
|
2160
|
-
|
|
2161
|
-
/**
|
|
2162
|
-
* Sets the cursor option for the aggregation query (ignored for < 2.6.0).
|
|
2163
|
-
*/
|
|
2164
|
-
cursor<DocType = any>(options?: Record<string, unknown>): Cursor<DocType>;
|
|
2165
|
-
|
|
2166
|
-
/** Executes the aggregate pipeline on the currently bound Model. */
|
|
2167
|
-
exec(callback?: Callback<R>): Promise<R>;
|
|
2168
|
-
|
|
2169
|
-
/** Execute the aggregation with explain */
|
|
2170
|
-
explain(callback?: Callback): Promise<any>;
|
|
2171
|
-
explain(verbosity?: string, callback?: Callback): Promise<any>;
|
|
2172
|
-
|
|
2173
|
-
/** Combines multiple aggregation pipelines. */
|
|
2174
|
-
facet(options: PipelineStage.Facet['$facet']): this;
|
|
2175
|
-
|
|
2176
|
-
/** Appends new custom $graphLookup operator(s) to this aggregate pipeline, performing a recursive search on a collection. */
|
|
2177
|
-
graphLookup(options: PipelineStage.GraphLookup['$graphLookup']): this;
|
|
2178
|
-
|
|
2179
|
-
/** Appends new custom $group operator to this aggregate pipeline. */
|
|
2180
|
-
group(arg: PipelineStage.Group['$group']): this;
|
|
2181
|
-
|
|
2182
|
-
/** Sets the hint option for the aggregation query (ignored for < 3.6.0) */
|
|
2183
|
-
hint(value: Record<string, unknown> | string): this;
|
|
2184
|
-
|
|
2185
|
-
/**
|
|
2186
|
-
* Appends a new $limit operator to this aggregate pipeline.
|
|
2187
|
-
* @param num maximum number of records to pass to the next stage
|
|
2188
|
-
*/
|
|
2189
|
-
limit(num: PipelineStage.Limit['$limit']): this;
|
|
2190
|
-
|
|
2191
|
-
/** Appends new custom $lookup operator to this aggregate pipeline. */
|
|
2192
|
-
lookup(options: PipelineStage.Lookup['$lookup']): this;
|
|
2193
|
-
|
|
2194
|
-
/**
|
|
2195
|
-
* Appends a new custom $match operator to this aggregate pipeline.
|
|
2196
|
-
* @param arg $match operator contents
|
|
2197
|
-
*/
|
|
2198
|
-
match(arg: PipelineStage.Match['$match']): this;
|
|
2199
|
-
|
|
2200
|
-
/**
|
|
2201
|
-
* Binds this aggregate to a model.
|
|
2202
|
-
* @param model the model to which the aggregate is to be bound
|
|
2203
|
-
*/
|
|
2204
|
-
model(model: any): this;
|
|
2205
|
-
|
|
2206
|
-
/**
|
|
2207
|
-
* Append a new $near operator to this aggregation pipeline
|
|
2208
|
-
* @param arg $near operator contents
|
|
2209
|
-
*/
|
|
2210
|
-
near(arg: { near?: number[]; distanceField: string; maxDistance?: number; query?: Record<string, any>; includeLocs?: string; num?: number; uniqueDocs?: boolean }): this;
|
|
2211
|
-
|
|
2212
|
-
/** Returns the current pipeline */
|
|
2213
|
-
pipeline(): any[];
|
|
2214
|
-
|
|
2215
|
-
/** Appends a new $project operator to this aggregate pipeline. */
|
|
2216
|
-
project(arg: PipelineStage.Project['$project']): this;
|
|
2217
|
-
|
|
2218
|
-
/** Sets the readPreference option for the aggregation query. */
|
|
2219
|
-
read(pref: string | mongodb.ReadPreferenceMode, tags?: any[]): this;
|
|
2220
|
-
|
|
2221
|
-
/** Sets the readConcern level for the aggregation query. */
|
|
2222
|
-
readConcern(level: string): this;
|
|
2223
|
-
|
|
2224
|
-
/** Appends a new $redact operator to this aggregate pipeline. */
|
|
2225
|
-
redact(expression: any, thenExpr: string | any, elseExpr: string | any): this;
|
|
2226
|
-
|
|
2227
|
-
/** Appends a new $replaceRoot operator to this aggregate pipeline. */
|
|
2228
|
-
replaceRoot(newRoot: PipelineStage.ReplaceRoot['$replaceRoot']['newRoot'] | string): this;
|
|
2229
|
-
|
|
2230
|
-
/**
|
|
2231
|
-
* Helper for [Atlas Text Search](https://docs.atlas.mongodb.com/reference/atlas-search/tutorial/)'s
|
|
2232
|
-
* `$search` stage.
|
|
2233
|
-
*/
|
|
2234
|
-
search(options: PipelineStage.Search['$search']): this;
|
|
2235
|
-
|
|
2236
|
-
/** Lets you set arbitrary options, for middleware or plugins. */
|
|
2237
|
-
option(value: Record<string, unknown>): this;
|
|
2238
|
-
|
|
2239
|
-
/** Appends new custom $sample operator to this aggregate pipeline. */
|
|
2240
|
-
sample(size: number): this;
|
|
2241
|
-
|
|
2242
|
-
/** Sets the session for this aggregation. Useful for [transactions](/docs/transactions.html). */
|
|
2243
|
-
session(session: mongodb.ClientSession | null): this;
|
|
2244
|
-
|
|
2245
|
-
/**
|
|
2246
|
-
* Appends a new $skip operator to this aggregate pipeline.
|
|
2247
|
-
* @param num number of records to skip before next stage
|
|
2248
|
-
*/
|
|
2249
|
-
skip(num: number): this;
|
|
2250
|
-
|
|
2251
|
-
/** Appends a new $sort operator to this aggregate pipeline. */
|
|
2252
|
-
sort(arg: string | Record<string, SortValues> | PipelineStage.Sort['$sort']): this;
|
|
2253
|
-
|
|
2254
|
-
/** Provides promise for aggregate. */
|
|
2255
|
-
then: Promise<R>['then'];
|
|
2256
|
-
|
|
2257
|
-
/**
|
|
2258
|
-
* Appends a new $sortByCount operator to this aggregate pipeline. Accepts either a string field name
|
|
2259
|
-
* or a pipeline object.
|
|
2260
|
-
*/
|
|
2261
|
-
sortByCount(arg: string | any): this;
|
|
2262
|
-
|
|
2263
|
-
/** Appends new $unionWith operator to this aggregate pipeline. */
|
|
2264
|
-
unionWith(options: any): this;
|
|
2265
|
-
|
|
2266
|
-
/** Appends new custom $unwind operator(s) to this aggregate pipeline. */
|
|
2267
|
-
unwind(...args: PipelineStage.Unwind['$unwind'][]): this;
|
|
2268
|
-
}
|
|
2269
|
-
|
|
2270
2255
|
class SchemaType {
|
|
2271
2256
|
/** SchemaType constructor */
|
|
2272
2257
|
constructor(path: string, options?: AnyObject, instance?: string);
|