mongoose 6.5.2 → 6.5.5
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/.mocharc.yml +2 -0
- package/dist/browser.umd.js +1148 -68091
- package/lib/aggregate.js +7 -7
- package/lib/browserDocument.js +1 -1
- package/lib/cast/boolean.js +1 -1
- package/lib/cast/number.js +1 -1
- package/lib/cast/string.js +1 -1
- package/lib/cast.js +3 -0
- package/lib/connection.js +19 -11
- package/lib/cursor/AggregationCursor.js +16 -5
- package/lib/cursor/QueryCursor.js +16 -5
- package/lib/document.js +31 -18
- package/lib/drivers/browser/objectid.js +2 -1
- package/lib/drivers/node-mongodb-native/ReadPreference.js +1 -1
- package/lib/drivers/node-mongodb-native/collection.js +6 -2
- package/lib/error/browserMissingSchema.js +1 -1
- package/lib/error/cast.js +2 -1
- package/lib/error/divergentArray.js +2 -1
- package/lib/error/missingSchema.js +2 -1
- package/lib/error/notFound.js +2 -1
- package/lib/error/overwriteModel.js +2 -1
- package/lib/error/strictPopulate.js +29 -0
- package/lib/error/validation.js +9 -7
- package/lib/error/validator.js +8 -4
- package/lib/helpers/clone.js +1 -1
- package/lib/helpers/discriminator/getConstructor.js +2 -1
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +7 -6
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +7 -6
- package/lib/helpers/document/compile.js +14 -2
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +5 -1
- package/lib/helpers/get.js +2 -1
- package/lib/helpers/getConstructorName.js +2 -1
- package/lib/helpers/indexes/isIndexEqual.js +6 -6
- package/lib/helpers/isBsonType.js +2 -1
- package/lib/helpers/isMongooseObject.js +2 -2
- package/lib/helpers/isObject.js +1 -1
- package/lib/helpers/isSimpleValidator.js +1 -1
- package/lib/helpers/model/applyHooks.js +11 -0
- package/lib/helpers/model/applyMethods.js +11 -1
- package/lib/helpers/model/applyStatics.js +2 -1
- package/lib/helpers/model/castBulkWrite.js +7 -2
- package/lib/helpers/model/discriminator.js +3 -1
- package/lib/helpers/path/flattenObjectWithDottedPaths.js +3 -2
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +5 -3
- package/lib/helpers/populate/assignVals.js +14 -3
- package/lib/helpers/populate/createPopulateQueryFilter.js +8 -2
- package/lib/helpers/populate/getModelsMapForPopulate.js +5 -4
- package/lib/helpers/populate/getSchemaTypes.js +3 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +5 -1
- package/lib/helpers/projection/hasIncludedChildren.js +4 -1
- package/lib/helpers/projection/isPathExcluded.js +3 -2
- package/lib/helpers/projection/isSubpath.js +2 -1
- package/lib/helpers/query/applyQueryMiddleware.js +3 -2
- package/lib/helpers/query/castUpdate.js +14 -8
- package/lib/helpers/query/completeMany.js +3 -2
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +7 -1
- package/lib/helpers/query/wrapThunk.js +3 -1
- package/lib/helpers/schema/getIndexes.js +7 -2
- package/lib/helpers/schema/getPath.js +4 -3
- package/lib/helpers/schema/idGetter.js +2 -1
- package/lib/helpers/setDefaultsOnInsert.js +15 -0
- package/lib/index.js +20 -12
- package/lib/model.js +219 -145
- package/lib/query.js +160 -65
- package/lib/queryhelpers.js +4 -4
- package/lib/schema/SubdocumentPath.js +1 -1
- package/lib/schema/array.js +2 -2
- package/lib/schema/date.js +2 -1
- package/lib/schema/documentarray.js +4 -3
- package/lib/schema/operators/helpers.js +2 -2
- package/lib/schema/operators/text.js +1 -1
- package/lib/schema/string.js +1 -1
- package/lib/schema.js +14 -5
- package/lib/schematype.js +17 -4
- package/lib/statemachine.js +13 -12
- package/lib/types/ArraySubdocument.js +13 -3
- package/lib/types/DocumentArray/methods/index.js +9 -5
- package/lib/types/array/methods/index.js +5 -4
- package/lib/types/map.js +3 -1
- package/lib/types/objectid.js +2 -2
- package/lib/types/subdocument.js +30 -8
- package/lib/utils.js +58 -31
- package/package.json +11 -11
- package/scripts/create-tarball.js +7 -0
- package/types/aggregate.d.ts +3 -3
- package/types/connection.d.ts +4 -4
- package/types/cursor.d.ts +1 -1
- package/types/document.d.ts +2 -2
- package/types/index.d.ts +13 -27
- package/types/indexes.d.ts +2 -2
- package/types/middlewares.d.ts +1 -1
- package/types/models.d.ts +14 -11
- package/types/pipelinestage.d.ts +1 -1
- package/types/query.d.ts +33 -16
package/types/models.d.ts
CHANGED
|
@@ -113,6 +113,8 @@ declare module 'mongoose' {
|
|
|
113
113
|
wtimeout?: number;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
interface RemoveOptions extends SessionOption, Omit<mongodb.DeleteOptions, 'session'> {}
|
|
117
|
+
|
|
116
118
|
const Model: Model<any>;
|
|
117
119
|
interface Model<T, TQueryHelpers = {}, TMethodsAndOverrides = {}, TVirtuals = {}, TSchema = any> extends
|
|
118
120
|
NodeJS.EventEmitter,
|
|
@@ -260,21 +262,21 @@ declare module 'mongoose' {
|
|
|
260
262
|
init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
261
263
|
|
|
262
264
|
/** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
|
|
263
|
-
insertMany<DocContents = T>(docs: Array<DocContents | T>, options: InsertManyOptions & { lean: true; }, callback: Callback<Array<MergeType<MergeType<T, DocContents>,
|
|
265
|
+
insertMany<DocContents = T>(docs: Array<DocContents | T>, options: InsertManyOptions & { lean: true; }, callback: Callback<Array<MergeType<MergeType<T, DocContents>, Require_id<T>>>>): void;
|
|
264
266
|
insertMany<DocContents = T>(docs: Array<DocContents | T>, options: InsertManyOptions & { rawResult: true; }, callback: Callback<mongodb.InsertManyResult<T>>): void;
|
|
265
|
-
insertMany<DocContents = T>(docs: Array<DocContents | T>, callback: Callback<Array<HydratedDocument<MergeType<MergeType<T, DocContents>,
|
|
266
|
-
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { lean: true; }, callback: Callback<Array<MergeType<MergeType<T, DocContents>,
|
|
267
|
+
insertMany<DocContents = T>(docs: Array<DocContents | T>, callback: Callback<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>): void;
|
|
268
|
+
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { lean: true; }, callback: Callback<Array<MergeType<MergeType<T, DocContents>, Require_id<T>>>>): void;
|
|
267
269
|
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { rawResult: true; }, callback: Callback<mongodb.InsertManyResult<T>>): void;
|
|
268
|
-
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { lean?: false | undefined }, callback: Callback<Array<HydratedDocument<MergeType<MergeType<T, DocContents>,
|
|
269
|
-
insertMany<DocContents = T>(doc: DocContents, callback: Callback<Array<HydratedDocument<MergeType<MergeType<T, DocContents>,
|
|
270
|
+
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { lean?: false | undefined }, callback: Callback<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>): void;
|
|
271
|
+
insertMany<DocContents = T>(doc: DocContents, callback: Callback<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>): void;
|
|
270
272
|
|
|
271
|
-
insertMany<DocContents = T>(docs: Array<DocContents | T>, options: InsertManyOptions & { lean: true; }): Promise<Array<MergeType<MergeType<T, DocContents>,
|
|
273
|
+
insertMany<DocContents = T>(docs: Array<DocContents | T>, options: InsertManyOptions & { lean: true; }): Promise<Array<MergeType<MergeType<T, DocContents>, Require_id<T>>>>;
|
|
272
274
|
insertMany<DocContents = T>(docs: Array<DocContents | T>, options: InsertManyOptions & { rawResult: true; }): Promise<mongodb.InsertManyResult<T>>;
|
|
273
|
-
insertMany<DocContents = T>(docs: Array<DocContents | T>): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>,
|
|
274
|
-
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { lean: true; }): Promise<Array<MergeType<MergeType<T, DocContents>,
|
|
275
|
+
insertMany<DocContents = T>(docs: Array<DocContents | T>): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>;
|
|
276
|
+
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { lean: true; }): Promise<Array<MergeType<MergeType<T, DocContents>, Require_id<T>>>>;
|
|
275
277
|
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions & { rawResult: true; }): Promise<mongodb.InsertManyResult<T>>;
|
|
276
|
-
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>,
|
|
277
|
-
insertMany<DocContents = T>(doc: DocContents): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>,
|
|
278
|
+
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>;
|
|
279
|
+
insertMany<DocContents = T>(doc: DocContents): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, Require_id<T>>, TMethodsAndOverrides, TVirtuals>>>;
|
|
278
280
|
|
|
279
281
|
/** The name of the model */
|
|
280
282
|
modelName: string;
|
|
@@ -392,6 +394,7 @@ declare module 'mongoose' {
|
|
|
392
394
|
): Promise<any>;
|
|
393
395
|
|
|
394
396
|
remove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: any, callback?: CallbackWithoutResult): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
397
|
+
remove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: any, options?: RemoveOptions, callback?: CallbackWithoutResult): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
|
|
395
398
|
|
|
396
399
|
/** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */
|
|
397
400
|
replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
@@ -399,7 +402,7 @@ declare module 'mongoose' {
|
|
|
399
402
|
replacement?: T | AnyObject,
|
|
400
403
|
options?: QueryOptions<T> | null,
|
|
401
404
|
callback?: Callback
|
|
402
|
-
): QueryWithHelpers<
|
|
405
|
+
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
|
|
403
406
|
|
|
404
407
|
/** Schema the model uses. */
|
|
405
408
|
schema: Schema<T>;
|
package/types/pipelinestage.d.ts
CHANGED
|
@@ -141,7 +141,7 @@ declare module 'mongoose' {
|
|
|
141
141
|
localField?: string
|
|
142
142
|
foreignField?: string
|
|
143
143
|
let?: Record<string, any>
|
|
144
|
-
pipeline?: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out
|
|
144
|
+
pipeline?: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out>[]
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
package/types/query.d.ts
CHANGED
|
@@ -173,7 +173,7 @@ declare module 'mongoose' {
|
|
|
173
173
|
_mongooseOptions: MongooseQueryOptions<DocType>;
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
|
-
* Returns a wrapper around a [mongodb driver cursor](
|
|
176
|
+
* Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html).
|
|
177
177
|
* A QueryCursor exposes a Streams3 interface, as well as a `.next()` function.
|
|
178
178
|
* This is equivalent to calling `.cursor()` with no arguments.
|
|
179
179
|
*/
|
|
@@ -244,7 +244,7 @@ declare module 'mongoose' {
|
|
|
244
244
|
countDocuments(callback?: Callback<number>): QueryWithHelpers<number, DocType, THelpers, RawDocType>;
|
|
245
245
|
|
|
246
246
|
/**
|
|
247
|
-
* Returns a wrapper around a [mongodb driver cursor](
|
|
247
|
+
* Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html).
|
|
248
248
|
* A QueryCursor exposes a Streams3 interface, as well as a `.next()` function.
|
|
249
249
|
*/
|
|
250
250
|
cursor(options?: QueryOptions<DocType>): Cursor<DocType, QueryOptions<DocType>>;
|
|
@@ -271,7 +271,7 @@ declare module 'mongoose' {
|
|
|
271
271
|
distinct<ReturnType = any>(field: string, filter?: FilterQuery<DocType>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, DocType, THelpers, RawDocType>;
|
|
272
272
|
|
|
273
273
|
/** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
274
|
-
elemMatch<K
|
|
274
|
+
elemMatch<K = string>(path: K, val: any): this;
|
|
275
275
|
elemMatch(val: Function | any): this;
|
|
276
276
|
|
|
277
277
|
/**
|
|
@@ -288,7 +288,7 @@ declare module 'mongoose' {
|
|
|
288
288
|
estimatedDocumentCount(options?: QueryOptions<DocType>, callback?: Callback<number>): QueryWithHelpers<number, DocType, THelpers, RawDocType>;
|
|
289
289
|
|
|
290
290
|
/** Specifies a `$exists` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
291
|
-
exists<K
|
|
291
|
+
exists<K = string>(path: K, val: boolean): this;
|
|
292
292
|
exists(val: boolean): this;
|
|
293
293
|
|
|
294
294
|
/**
|
|
@@ -368,6 +368,23 @@ declare module 'mongoose' {
|
|
|
368
368
|
callback?: (err: CallbackError, doc: DocType | null, res: ModifyResult<DocType>) => void
|
|
369
369
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
370
370
|
|
|
371
|
+
/** Declares the query a findById operation. When executed, the document with the given `_id` is passed to the callback. */
|
|
372
|
+
findById(
|
|
373
|
+
id: mongodb.ObjectId | any,
|
|
374
|
+
projection?: ProjectionType<DocType> | null,
|
|
375
|
+
options?: QueryOptions<DocType> | null,
|
|
376
|
+
callback?: Callback<DocType | null>
|
|
377
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
378
|
+
findById(
|
|
379
|
+
id: mongodb.ObjectId | any,
|
|
380
|
+
projection?: ProjectionType<DocType> | null,
|
|
381
|
+
callback?: Callback<DocType | null>
|
|
382
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
383
|
+
findById(
|
|
384
|
+
id: mongodb.ObjectId | any,
|
|
385
|
+
callback?: Callback<DocType | null>
|
|
386
|
+
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
387
|
+
|
|
371
388
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
372
389
|
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions<DocType> | null, callback?: (err: CallbackError, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
|
|
373
390
|
|
|
@@ -403,18 +420,18 @@ declare module 'mongoose' {
|
|
|
403
420
|
getUpdate(): UpdateQuery<DocType> | UpdateWithAggregationPipeline | null;
|
|
404
421
|
|
|
405
422
|
/** Specifies a `$gt` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
406
|
-
gt<K
|
|
423
|
+
gt<K = string>(path: K, val: any): this;
|
|
407
424
|
gt(val: number): this;
|
|
408
425
|
|
|
409
426
|
/** Specifies a `$gte` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
410
|
-
gte<K
|
|
427
|
+
gte<K = string>(path: K, val: any): this;
|
|
411
428
|
gte(val: number): this;
|
|
412
429
|
|
|
413
430
|
/** Sets query hints. */
|
|
414
431
|
hint(val: any): this;
|
|
415
432
|
|
|
416
433
|
/** Specifies an `$in` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
417
|
-
in<K
|
|
434
|
+
in<K = string>(path: K, val: any[]): this;
|
|
418
435
|
in(val: Array<any>): this;
|
|
419
436
|
|
|
420
437
|
/** Declares an intersects query for `geometry()`. */
|
|
@@ -430,11 +447,11 @@ declare module 'mongoose' {
|
|
|
430
447
|
limit(val: number): this;
|
|
431
448
|
|
|
432
449
|
/** Specifies a `$lt` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
433
|
-
lt<K
|
|
450
|
+
lt<K = string>(path: K, val: any): this;
|
|
434
451
|
lt(val: number): this;
|
|
435
452
|
|
|
436
453
|
/** Specifies a `$lte` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
437
|
-
lte<K
|
|
454
|
+
lte<K = string>(path: K, val: any): this;
|
|
438
455
|
lte(val: number): this;
|
|
439
456
|
|
|
440
457
|
/**
|
|
@@ -461,7 +478,7 @@ declare module 'mongoose' {
|
|
|
461
478
|
merge(source: Query<any, any> | FilterQuery<DocType>): this;
|
|
462
479
|
|
|
463
480
|
/** Specifies a `$mod` condition, filters documents for documents whose `path` property is a number that is equal to `remainder` modulo `divisor`. */
|
|
464
|
-
mod<K
|
|
481
|
+
mod<K = string>(path: K, val: number): this;
|
|
465
482
|
mod(val: Array<number>): this;
|
|
466
483
|
|
|
467
484
|
/** The model this query was created from */
|
|
@@ -474,15 +491,15 @@ declare module 'mongoose' {
|
|
|
474
491
|
mongooseOptions(val?: MongooseQueryOptions): MongooseQueryOptions;
|
|
475
492
|
|
|
476
493
|
/** Specifies a `$ne` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
477
|
-
ne<K
|
|
494
|
+
ne<K = string>(path: K, val: any): this;
|
|
478
495
|
ne(val: any): this;
|
|
479
496
|
|
|
480
497
|
/** Specifies a `$near` or `$nearSphere` condition */
|
|
481
|
-
near<K
|
|
498
|
+
near<K = string>(path: K, val: any): this;
|
|
482
499
|
near(val: any): this;
|
|
483
500
|
|
|
484
501
|
/** Specifies an `$nin` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
485
|
-
nin<K
|
|
502
|
+
nin<K = string>(path: K, val: any[]): this;
|
|
486
503
|
nin(val: Array<any>): this;
|
|
487
504
|
|
|
488
505
|
/** Specifies arguments for an `$nor` condition. */
|
|
@@ -518,7 +535,7 @@ declare module 'mongoose' {
|
|
|
518
535
|
readConcern(level: string): this;
|
|
519
536
|
|
|
520
537
|
/** Specifies a `$regex` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
521
|
-
regex<K
|
|
538
|
+
regex<K = string>(path: K, val: RegExp): this;
|
|
522
539
|
regex(val: string | RegExp): this;
|
|
523
540
|
|
|
524
541
|
/**
|
|
@@ -570,7 +587,7 @@ declare module 'mongoose' {
|
|
|
570
587
|
setUpdate(update: UpdateQuery<DocType> | UpdateWithAggregationPipeline): void;
|
|
571
588
|
|
|
572
589
|
/** Specifies an `$size` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
573
|
-
size<K
|
|
590
|
+
size<K = string>(path: K, val: number): this;
|
|
574
591
|
size(val: number): this;
|
|
575
592
|
|
|
576
593
|
/** Specifies the number of documents to skip. */
|
|
@@ -599,7 +616,7 @@ declare module 'mongoose' {
|
|
|
599
616
|
then: Promise<ResultType>['then'];
|
|
600
617
|
|
|
601
618
|
/** Converts this query to a customized, reusable query constructor with all arguments and options retained. */
|
|
602
|
-
toConstructor():
|
|
619
|
+
toConstructor(): typeof this;
|
|
603
620
|
|
|
604
621
|
/** Declare and/or execute this query as an update() operation. */
|
|
605
622
|
update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
|