mongoose 9.2.3 → 9.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/lib/aggregate.js +68 -45
- package/lib/cast/bigint.js +2 -2
- package/lib/cast/boolean.js +3 -3
- package/lib/cast/double.js +2 -2
- package/lib/cast/int32.js +2 -2
- package/lib/cast/number.js +2 -2
- package/lib/cast/string.js +2 -2
- package/lib/cast.js +6 -6
- package/lib/collection.js +4 -4
- package/lib/connection.js +64 -78
- package/lib/cursor/aggregationCursor.js +8 -8
- package/lib/cursor/changeStream.js +55 -35
- package/lib/cursor/queryCursor.js +9 -9
- package/lib/document.js +394 -381
- package/lib/drivers/node-mongodb-native/collection.js +3 -3
- package/lib/drivers/node-mongodb-native/connection.js +8 -8
- package/lib/error/cast.js +2 -2
- package/lib/error/createCollectionsError.js +2 -2
- package/lib/error/divergentArray.js +1 -1
- package/lib/error/eachAsyncMultiError.js +1 -1
- package/lib/error/index.js +2 -2
- package/lib/error/invalidSchemaOption.js +1 -1
- package/lib/error/missingSchema.js +1 -1
- package/lib/error/objectParameter.js +3 -3
- package/lib/error/overwriteModel.js +1 -1
- package/lib/error/setOptionError.js +3 -3
- package/lib/error/strict.js +3 -3
- package/lib/error/strictPopulate.js +2 -2
- package/lib/error/syncIndexes.js +2 -2
- package/lib/error/validation.js +2 -2
- package/lib/error/validator.js +1 -1
- package/lib/error/version.js +2 -2
- package/lib/helpers/buildMiddlewareFilter.js +2 -2
- package/lib/helpers/clone.js +4 -4
- package/lib/helpers/createJSONSchemaTypeDefinition.js +4 -4
- package/lib/helpers/cursor/eachAsync.js +3 -3
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +3 -3
- package/lib/helpers/document/applyTimestamps.js +9 -9
- package/lib/helpers/document/applyVirtuals.js +6 -6
- package/lib/helpers/document/compile.js +10 -10
- package/lib/helpers/document/getDeepestSubdocumentForPath.js +2 -2
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
- package/lib/helpers/indexes/isIndexEqual.js +3 -3
- package/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
- package/lib/helpers/isMongooseObject.js +1 -1
- package/lib/helpers/isObject.js +2 -2
- package/lib/helpers/isSimpleValidator.js +2 -2
- package/lib/helpers/minimize.js +2 -2
- package/lib/helpers/model/applyHooks.js +1 -1
- package/lib/helpers/model/castBulkWrite.js +2 -2
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +2 -2
- package/lib/helpers/populate/assignVals.js +6 -6
- package/lib/helpers/populate/createPopulateQueryFilter.js +2 -2
- package/lib/helpers/populate/getModelsMapForPopulate.js +12 -12
- package/lib/helpers/populate/getSchemaTypes.js +1 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/isPathExcluded.js +3 -3
- package/lib/helpers/projection/isSubpath.js +1 -1
- package/lib/helpers/query/castUpdate.js +14 -14
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +5 -5
- package/lib/helpers/query/handleImmutable.js +6 -6
- package/lib/helpers/schema/getIndexes.js +1 -1
- package/lib/helpers/schema/getSubdocumentStrictValue.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +10 -8
- package/lib/helpers/update/modifiedPaths.js +2 -2
- package/lib/helpers/update/removeUnusedArrayFilters.js +7 -2
- package/lib/helpers/updateValidators.js +3 -10
- package/lib/model.js +323 -298
- package/lib/mongoose.js +55 -57
- package/lib/options/schemaArrayOptions.js +2 -2
- package/lib/options/schemaBufferOptions.js +1 -1
- package/lib/options/schemaDocumentArrayOptions.js +23 -0
- package/lib/options/schemaNumberOptions.js +3 -3
- package/lib/options/schemaObjectIdOptions.js +2 -2
- package/lib/options/schemaStringOptions.js +6 -6
- package/lib/options/schemaSubdocumentOptions.js +23 -0
- package/lib/options/schemaTypeOptions.js +13 -13
- package/lib/options/virtualOptions.js +11 -11
- package/lib/plugins/index.js +0 -1
- package/lib/query.js +349 -310
- package/lib/queryHelpers.js +4 -4
- package/lib/schema/array.js +18 -18
- package/lib/schema/bigint.js +13 -13
- package/lib/schema/boolean.js +13 -13
- package/lib/schema/buffer.js +15 -15
- package/lib/schema/date.js +16 -16
- package/lib/schema/decimal128.js +13 -13
- package/lib/schema/documentArray.js +16 -16
- package/lib/schema/documentArrayElement.js +5 -6
- package/lib/schema/double.js +12 -12
- package/lib/schema/int32.js +13 -13
- package/lib/schema/map.js +10 -10
- package/lib/schema/mixed.js +10 -10
- package/lib/schema/number.js +18 -18
- package/lib/schema/objectId.js +14 -14
- package/lib/schema/operators/text.js +3 -3
- package/lib/schema/string.js +17 -17
- package/lib/schema/subdocument.js +13 -13
- package/lib/schema/union.js +3 -3
- package/lib/schema/uuid.js +16 -16
- package/lib/schema.js +77 -77
- package/lib/schemaType.js +76 -68
- package/lib/stateMachine.js +5 -8
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +12 -12
- package/lib/types/arraySubdocument.js +8 -8
- package/lib/types/buffer.js +4 -4
- package/lib/types/documentArray/index.js +1 -1
- package/lib/types/documentArray/methods/index.js +5 -5
- package/lib/types/map.js +3 -3
- package/lib/types/subdocument.js +11 -11
- package/lib/utils.js +45 -45
- package/lib/virtualType.js +18 -18
- package/package.json +11 -7
- package/types/aggregate.d.ts +3 -0
- package/types/connection.d.ts +2 -2
- package/types/cursor.d.ts +1 -1
- package/types/document.d.ts +4 -4
- package/types/index.d.ts +17 -16
- package/types/indexes.d.ts +1 -1
- package/types/inferhydrateddoctype.d.ts +23 -3
- package/types/inferrawdoctype.d.ts +32 -10
- package/types/inferschematype.d.ts +41 -4
- package/types/models.d.ts +7 -4
- package/types/pipelinestage.d.ts +3 -2
- package/types/query.d.ts +2 -2
- package/types/schemaoptions.d.ts +1 -1
- package/types/schematypes.d.ts +3 -0
- package/types/virtuals.d.ts +10 -10
- package/lib/plugins/validateBeforeSave.js +0 -47
package/lib/aggregate.js
CHANGED
|
@@ -46,7 +46,7 @@ const validRedactStringValues = new Set(['$$DESCEND', '$$PRUNE', '$$KEEP']);
|
|
|
46
46
|
* new Aggregate([{ $match: { _id: new mongoose.Types.ObjectId('00000000000000000000000a') } }]);
|
|
47
47
|
*
|
|
48
48
|
* @see MongoDB https://www.mongodb.com/docs/manual/applications/aggregation/
|
|
49
|
-
* @see driver https://mongodb.github.io/node-mongodb-native/
|
|
49
|
+
* @see driver https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#aggregate
|
|
50
50
|
* @param {Array} [pipeline] aggregation pipeline as an array of objects
|
|
51
51
|
* @param {Model|Connection} [modelOrConn] the model or connection to use with this aggregate.
|
|
52
52
|
* @api public
|
|
@@ -159,7 +159,7 @@ Aggregate.prototype.model = function(model) {
|
|
|
159
159
|
* const pipeline = [{ $match: { daw: 'Logic Audio X' }} ];
|
|
160
160
|
* aggregate.append(pipeline);
|
|
161
161
|
*
|
|
162
|
-
* @param {...
|
|
162
|
+
* @param {...object|object[]} ops operator(s) to append. Can either be a spread of objects or a single parameter of a object array.
|
|
163
163
|
* @return {Aggregate}
|
|
164
164
|
* @api public
|
|
165
165
|
*/
|
|
@@ -196,7 +196,7 @@ Aggregate.prototype.append = function() {
|
|
|
196
196
|
* // etc
|
|
197
197
|
* aggregate.addFields({ salary_k: { $divide: [ "$salary", 1000 ] } });
|
|
198
198
|
*
|
|
199
|
-
* @param {
|
|
199
|
+
* @param {object} arg field specification
|
|
200
200
|
* @see $addFields https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/
|
|
201
201
|
* @return {Aggregate}
|
|
202
202
|
* @api public
|
|
@@ -234,7 +234,7 @@ Aggregate.prototype.addFields = function(arg) {
|
|
|
234
234
|
* // etc
|
|
235
235
|
* aggregate.project({ salary_k: { $divide: [ "$salary", 1000 ] } });
|
|
236
236
|
*
|
|
237
|
-
* @param {
|
|
237
|
+
* @param {object|string} arg field specification
|
|
238
238
|
* @see projection https://www.mongodb.com/docs/manual/reference/aggregation/project/
|
|
239
239
|
* @return {Aggregate}
|
|
240
240
|
* @api public
|
|
@@ -276,7 +276,7 @@ Aggregate.prototype.project = function(arg) {
|
|
|
276
276
|
* @method group
|
|
277
277
|
* @memberOf Aggregate
|
|
278
278
|
* @instance
|
|
279
|
-
* @param {
|
|
279
|
+
* @param {object} arg $group operator contents
|
|
280
280
|
* @return {Aggregate}
|
|
281
281
|
* @api public
|
|
282
282
|
*/
|
|
@@ -292,7 +292,7 @@ Aggregate.prototype.project = function(arg) {
|
|
|
292
292
|
* @method match
|
|
293
293
|
* @memberOf Aggregate
|
|
294
294
|
* @instance
|
|
295
|
-
* @param {
|
|
295
|
+
* @param {object} arg $match operator contents
|
|
296
296
|
* @return {Aggregate}
|
|
297
297
|
* @api public
|
|
298
298
|
*/
|
|
@@ -308,7 +308,7 @@ Aggregate.prototype.project = function(arg) {
|
|
|
308
308
|
* @method skip
|
|
309
309
|
* @memberOf Aggregate
|
|
310
310
|
* @instance
|
|
311
|
-
* @param {
|
|
311
|
+
* @param {number} num number of records to skip before next stage
|
|
312
312
|
* @return {Aggregate}
|
|
313
313
|
* @api public
|
|
314
314
|
*/
|
|
@@ -324,7 +324,7 @@ Aggregate.prototype.project = function(arg) {
|
|
|
324
324
|
* @method limit
|
|
325
325
|
* @memberOf Aggregate
|
|
326
326
|
* @instance
|
|
327
|
-
* @param {
|
|
327
|
+
* @param {number} num maximum number of records to pass to the next stage
|
|
328
328
|
* @return {Aggregate}
|
|
329
329
|
* @api public
|
|
330
330
|
*/
|
|
@@ -348,7 +348,7 @@ Aggregate.prototype.project = function(arg) {
|
|
|
348
348
|
* @method densify
|
|
349
349
|
* @memberOf Aggregate
|
|
350
350
|
* @instance
|
|
351
|
-
* @param {
|
|
351
|
+
* @param {object} arg $densify operator contents
|
|
352
352
|
* @return {Aggregate}
|
|
353
353
|
* @api public
|
|
354
354
|
*/
|
|
@@ -370,7 +370,7 @@ Aggregate.prototype.project = function(arg) {
|
|
|
370
370
|
* @method fill
|
|
371
371
|
* @memberOf Aggregate
|
|
372
372
|
* @instance
|
|
373
|
-
* @param {
|
|
373
|
+
* @param {object} arg $fill operator contents
|
|
374
374
|
* @return {Aggregate}
|
|
375
375
|
* @api public
|
|
376
376
|
*/
|
|
@@ -397,8 +397,8 @@ Aggregate.prototype.project = function(arg) {
|
|
|
397
397
|
* @method near
|
|
398
398
|
* @memberOf Aggregate
|
|
399
399
|
* @instance
|
|
400
|
-
* @param {
|
|
401
|
-
* @param {
|
|
400
|
+
* @param {object} arg
|
|
401
|
+
* @param {object|number[]} arg.near GeoJSON point or coordinates array
|
|
402
402
|
* @return {Aggregate}
|
|
403
403
|
* @api public
|
|
404
404
|
*/
|
|
@@ -445,7 +445,7 @@ Aggregate.prototype.near = function(arg) {
|
|
|
445
445
|
* aggregate.unwind({ path: '$tags', preserveNullAndEmptyArrays: true });
|
|
446
446
|
*
|
|
447
447
|
* @see $unwind https://www.mongodb.com/docs/manual/reference/aggregation/unwind/
|
|
448
|
-
* @param {
|
|
448
|
+
* @param {string|object|string[]|object[]} fields the field(s) to unwind, either as field names or as [objects with options](https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#document-operand-with-options). If passing a string, prefixing the field name with '$' is optional. If passing an object, `path` must start with '$'.
|
|
449
449
|
* @return {Aggregate}
|
|
450
450
|
* @api public
|
|
451
451
|
*/
|
|
@@ -484,7 +484,7 @@ Aggregate.prototype.unwind = function() {
|
|
|
484
484
|
* aggregate.replaceRoot({ x: { $concat: ['$this', '$that'] } });
|
|
485
485
|
*
|
|
486
486
|
* @see $replaceRoot https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot
|
|
487
|
-
* @param {
|
|
487
|
+
* @param {string|object} newRoot the field or document which will become the new root document
|
|
488
488
|
* @return {Aggregate}
|
|
489
489
|
* @api public
|
|
490
490
|
*/
|
|
@@ -513,7 +513,7 @@ Aggregate.prototype.replaceRoot = function(newRoot) {
|
|
|
513
513
|
* aggregate.count("userCount");
|
|
514
514
|
*
|
|
515
515
|
* @see $count https://www.mongodb.com/docs/manual/reference/operator/aggregation/count
|
|
516
|
-
* @param {
|
|
516
|
+
* @param {string} fieldName The name of the output field which has the count as its value. It must be a non-empty string, must not start with $ and must not contain the . character.
|
|
517
517
|
* @return {Aggregate}
|
|
518
518
|
* @api public
|
|
519
519
|
*/
|
|
@@ -535,7 +535,7 @@ Aggregate.prototype.count = function(fieldName) {
|
|
|
535
535
|
* aggregate.sortByCount({ $mergeObjects: [ "$employee", "$business" ] })
|
|
536
536
|
*
|
|
537
537
|
* @see $sortByCount https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/
|
|
538
|
-
* @param {
|
|
538
|
+
* @param {object|string} arg
|
|
539
539
|
* @return {Aggregate} this
|
|
540
540
|
* @api public
|
|
541
541
|
*/
|
|
@@ -561,7 +561,7 @@ Aggregate.prototype.sortByCount = function(arg) {
|
|
|
561
561
|
* aggregate.lookup({ from: 'users', localField: 'userId', foreignField: '_id', as: 'users' });
|
|
562
562
|
*
|
|
563
563
|
* @see $lookup https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#pipe._S_lookup
|
|
564
|
-
* @param {
|
|
564
|
+
* @param {object} options to $lookup as described in the above link
|
|
565
565
|
* @return {Aggregate}
|
|
566
566
|
* @api public
|
|
567
567
|
*/
|
|
@@ -581,7 +581,7 @@ Aggregate.prototype.lookup = function(options) {
|
|
|
581
581
|
* aggregate.graphLookup({ from: 'courses', startWith: '$prerequisite', connectFromField: 'prerequisite', connectToField: 'name', as: 'prerequisites', maxDepth: 3 }) // this will recursively search the 'courses' collection up to 3 prerequisites
|
|
582
582
|
*
|
|
583
583
|
* @see $graphLookup https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#pipe._S_graphLookup
|
|
584
|
-
* @param {
|
|
584
|
+
* @param {object} options to $graphLookup as described in the above link
|
|
585
585
|
* @return {Aggregate}
|
|
586
586
|
* @api public
|
|
587
587
|
*/
|
|
@@ -614,7 +614,7 @@ Aggregate.prototype.graphLookup = function(options) {
|
|
|
614
614
|
* aggregate.sample(3); // Add a pipeline that picks 3 random documents
|
|
615
615
|
*
|
|
616
616
|
* @see $sample https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/#pipe._S_sample
|
|
617
|
-
* @param {
|
|
617
|
+
* @param {number} size number of random documents to pick
|
|
618
618
|
* @return {Aggregate}
|
|
619
619
|
* @api public
|
|
620
620
|
*/
|
|
@@ -637,7 +637,7 @@ Aggregate.prototype.sample = function(size) {
|
|
|
637
637
|
* aggregate.sort('field -test');
|
|
638
638
|
*
|
|
639
639
|
* @see $sort https://www.mongodb.com/docs/manual/reference/aggregation/sort/
|
|
640
|
-
* @param {
|
|
640
|
+
* @param {object|string} arg
|
|
641
641
|
* @return {Aggregate} this
|
|
642
642
|
* @api public
|
|
643
643
|
*/
|
|
@@ -683,7 +683,7 @@ Aggregate.prototype.sort = function(arg) {
|
|
|
683
683
|
* aggregate.unionWith({ coll: 'users', pipeline: [ { $match: { _id: 1 } } ] });
|
|
684
684
|
*
|
|
685
685
|
* @see $unionWith https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith
|
|
686
|
-
* @param {
|
|
686
|
+
* @param {object} options to $unionWith query as described in the above link
|
|
687
687
|
* @return {Aggregate}
|
|
688
688
|
* @api public
|
|
689
689
|
*/
|
|
@@ -700,7 +700,7 @@ Aggregate.prototype.unionWith = function(options) {
|
|
|
700
700
|
*
|
|
701
701
|
* await Model.aggregate(pipeline).read('primaryPreferred');
|
|
702
702
|
*
|
|
703
|
-
* @param {
|
|
703
|
+
* @param {string|ReadPreference} pref one of the listed preference options or their aliases
|
|
704
704
|
* @param {Array} [tags] optional tags for this query.
|
|
705
705
|
* @return {Aggregate} this
|
|
706
706
|
* @api public
|
|
@@ -749,9 +749,9 @@ Aggregate.prototype.readConcern = function(level) {
|
|
|
749
749
|
* // $redact often comes with $cond operator, you can also use the following syntax provided by mongoose
|
|
750
750
|
* await Model.aggregate(pipeline).redact({ $eq: [ '$level', 5 ] }, '$$PRUNE', '$$DESCEND');
|
|
751
751
|
*
|
|
752
|
-
* @param {
|
|
753
|
-
* @param {
|
|
754
|
-
* @param {
|
|
752
|
+
* @param {object} expression redact options or conditional expression
|
|
753
|
+
* @param {string|object} [thenExpr] true case for the condition
|
|
754
|
+
* @param {string|object} [elseExpr] false case for the condition
|
|
755
755
|
* @return {Aggregate} this
|
|
756
756
|
* @see $redact https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/
|
|
757
757
|
* @api public
|
|
@@ -839,7 +839,7 @@ Aggregate.prototype.explain = async function explain(verbosity) {
|
|
|
839
839
|
*
|
|
840
840
|
* await Model.aggregate([{ $match: { foo: 'bar' } }]).allowDiskUse(true);
|
|
841
841
|
*
|
|
842
|
-
* @param {
|
|
842
|
+
* @param {boolean} value Should tell server it can use hard drive to store data during aggregation.
|
|
843
843
|
* @return {Aggregate} this
|
|
844
844
|
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/aggregate/
|
|
845
845
|
*/
|
|
@@ -856,7 +856,7 @@ Aggregate.prototype.allowDiskUse = function(value) {
|
|
|
856
856
|
*
|
|
857
857
|
* Model.aggregate(..).hint({ qty: 1, category: 1 }).exec();
|
|
858
858
|
*
|
|
859
|
-
* @param {
|
|
859
|
+
* @param {object|string} value a hint object or the index name
|
|
860
860
|
* @return {Aggregate} this
|
|
861
861
|
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/aggregate/
|
|
862
862
|
*/
|
|
@@ -896,14 +896,14 @@ Aggregate.prototype.session = function(session) {
|
|
|
896
896
|
* const agg = Model.aggregate(..).option({ allowDiskUse: true }); // Set the `allowDiskUse` option
|
|
897
897
|
* agg.options; // `{ allowDiskUse: true }`
|
|
898
898
|
*
|
|
899
|
-
* @param {
|
|
900
|
-
* @param {
|
|
901
|
-
* @param {
|
|
902
|
-
* @param {
|
|
899
|
+
* @param {object} options keys to merge into current options
|
|
900
|
+
* @param {number} [options.maxTimeMS] number limits the time this aggregation will run, see [MongoDB docs on `maxTimeMS`](https://www.mongodb.com/docs/manual/reference/operator/meta/maxTimeMS/)
|
|
901
|
+
* @param {boolean} [options.allowDiskUse] boolean if true, the MongoDB server will use the hard drive to store data during this aggregation
|
|
902
|
+
* @param {object} [options.collation] object see [`Aggregate.prototype.collation()`](https://mongoosejs.com/docs/api/aggregate.html#Aggregate.prototype.collation())
|
|
903
903
|
* @param {ClientSession} [options.session] ClientSession see [`Aggregate.prototype.session()`](https://mongoosejs.com/docs/api/aggregate.html#Aggregate.prototype.session())
|
|
904
|
-
* @param {
|
|
905
|
-
* @param {
|
|
906
|
-
* @param {
|
|
904
|
+
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
905
|
+
* @param {boolean} [options.middleware.pre=true] set to `false` to skip only pre hooks
|
|
906
|
+
* @param {boolean} [options.middleware.post=true] set to `false` to skip only post hooks
|
|
907
907
|
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/aggregate/
|
|
908
908
|
* @return {Aggregate} this
|
|
909
909
|
* @api public
|
|
@@ -928,12 +928,12 @@ Aggregate.prototype.option = function(value) {
|
|
|
928
928
|
* // use doc
|
|
929
929
|
* });
|
|
930
930
|
*
|
|
931
|
-
* @param {
|
|
932
|
-
* @param {
|
|
933
|
-
* @param {
|
|
931
|
+
* @param {object} options
|
|
932
|
+
* @param {number} [options.batchSize] set the cursor batch size
|
|
933
|
+
* @param {boolean} [options.useMongooseAggCursor] use experimental mongoose-specific aggregation cursor (for `eachAsync()` and other query cursor semantics)
|
|
934
934
|
* @return {AggregationCursor} cursor representing this aggregation
|
|
935
935
|
* @api public
|
|
936
|
-
* @see mongodb https://mongodb.github.io/node-mongodb-native/
|
|
936
|
+
* @see mongodb https://mongodb.github.io/node-mongodb-native/7.0/classes/AggregationCursor.html
|
|
937
937
|
*/
|
|
938
938
|
|
|
939
939
|
Aggregate.prototype.cursor = function(options) {
|
|
@@ -949,10 +949,10 @@ Aggregate.prototype.cursor = function(options) {
|
|
|
949
949
|
*
|
|
950
950
|
* const res = await Model.aggregate(pipeline).collation({ locale: 'en_US', strength: 1 });
|
|
951
951
|
*
|
|
952
|
-
* @param {
|
|
952
|
+
* @param {object} collation options
|
|
953
953
|
* @return {Aggregate} this
|
|
954
954
|
* @api public
|
|
955
|
-
* @see mongodb https://mongodb.github.io/node-mongodb-native/
|
|
955
|
+
* @see mongodb https://mongodb.github.io/node-mongodb-native/7.0/interfaces/CollationOptions.html
|
|
956
956
|
*/
|
|
957
957
|
|
|
958
958
|
Aggregate.prototype.collation = function(collation) {
|
|
@@ -972,7 +972,7 @@ Aggregate.prototype.collation = function(collation) {
|
|
|
972
972
|
*
|
|
973
973
|
* // Output: { books: [...], price: [{...}, {...}] }
|
|
974
974
|
*
|
|
975
|
-
* @param {
|
|
975
|
+
* @param {object} facet options
|
|
976
976
|
* @return {Aggregate} this
|
|
977
977
|
* @see $facet https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/
|
|
978
978
|
* @api public
|
|
@@ -998,7 +998,7 @@ Aggregate.prototype.facet = function(options) {
|
|
|
998
998
|
*
|
|
999
999
|
* // Output: [{ plot: '...', title: '...' }]
|
|
1000
1000
|
*
|
|
1001
|
-
* @param {
|
|
1001
|
+
* @param {object} $search options
|
|
1002
1002
|
* @return {Aggregate} this
|
|
1003
1003
|
* @see $search https://www.mongodb.com/docs/atlas/atlas-search/tutorial/
|
|
1004
1004
|
* @api public
|
|
@@ -1015,7 +1015,7 @@ Aggregate.prototype.search = function(options) {
|
|
|
1015
1015
|
*
|
|
1016
1016
|
* MyModel.aggregate().match({ test: 1 }).pipeline(); // [{ $match: { test: 1 } }]
|
|
1017
1017
|
*
|
|
1018
|
-
* @return {
|
|
1018
|
+
* @return {PipelineStage[]} The current pipeline similar to the operation that will be executed
|
|
1019
1019
|
* @api public
|
|
1020
1020
|
*/
|
|
1021
1021
|
|
|
@@ -1023,6 +1023,29 @@ Aggregate.prototype.pipeline = function() {
|
|
|
1023
1023
|
return this._pipeline;
|
|
1024
1024
|
};
|
|
1025
1025
|
|
|
1026
|
+
/**
|
|
1027
|
+
* Returns the current pipeline as a `$unionWith`-safe pipeline.
|
|
1028
|
+
* Throws if this pipeline contains `$out` or `$merge`.
|
|
1029
|
+
*
|
|
1030
|
+
* #### Example:
|
|
1031
|
+
*
|
|
1032
|
+
* const base = MyModel.aggregate().match({ test: 1 });
|
|
1033
|
+
* base.pipelineForUnionWith(); // [{ $match: { test: 1 } }]
|
|
1034
|
+
*
|
|
1035
|
+
* @return {Array} The current pipeline with `$unionWith` stage restrictions
|
|
1036
|
+
* @api public
|
|
1037
|
+
*/
|
|
1038
|
+
|
|
1039
|
+
Aggregate.prototype.pipelineForUnionWith = function pipelineForUnionWith() {
|
|
1040
|
+
for (const stage of this._pipeline) {
|
|
1041
|
+
if (stage?.$out != null || stage?.$merge != null) {
|
|
1042
|
+
throw new MongooseError('Aggregate pipeline for $unionWith cannot include `$out` or `$merge` stages');
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
return this._pipeline;
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1026
1049
|
/**
|
|
1027
1050
|
* Executes the aggregate pipeline on the currently bound Model.
|
|
1028
1051
|
*
|
|
@@ -1170,8 +1193,8 @@ Aggregate.prototype[Symbol.asyncIterator] = function() {
|
|
|
1170
1193
|
/**
|
|
1171
1194
|
* Checks whether an object is likely a pipeline operator
|
|
1172
1195
|
*
|
|
1173
|
-
* @param {
|
|
1174
|
-
* @return {
|
|
1196
|
+
* @param {object} obj object to check
|
|
1197
|
+
* @return {boolean}
|
|
1175
1198
|
* @api private
|
|
1176
1199
|
*/
|
|
1177
1200
|
|
package/lib/cast/bigint.js
CHANGED
|
@@ -6,8 +6,8 @@ const { Long } = require('mongodb/lib/bson');
|
|
|
6
6
|
* Given a value, cast it to a BigInt, or throw an `Error` if the value
|
|
7
7
|
* cannot be casted. `null` and `undefined` are considered valid.
|
|
8
8
|
*
|
|
9
|
-
* @param {
|
|
10
|
-
* @return {
|
|
9
|
+
* @param {any} value
|
|
10
|
+
* @return {bigint|null|undefined}
|
|
11
11
|
* @throws {Error} if `value` is not one of the allowed values
|
|
12
12
|
* @api private
|
|
13
13
|
*/
|
package/lib/cast/boolean.js
CHANGED
|
@@ -6,9 +6,9 @@ const CastError = require('../error/cast');
|
|
|
6
6
|
* Given a value, cast it to a boolean, or throw a `CastError` if the value
|
|
7
7
|
* cannot be casted. `null` and `undefined` are considered valid.
|
|
8
8
|
*
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {
|
|
11
|
-
* @return {
|
|
9
|
+
* @param {any} value
|
|
10
|
+
* @param {string} [path] optional the path to set on the CastError
|
|
11
|
+
* @return {boolean|null|undefined}
|
|
12
12
|
* @throws {CastError} if `value` is not one of the allowed values
|
|
13
13
|
* @api private
|
|
14
14
|
*/
|
package/lib/cast/double.js
CHANGED
|
@@ -8,8 +8,8 @@ const isBsonType = require('../helpers/isBsonType');
|
|
|
8
8
|
* Given a value, cast it to a IEEE 754-2008 floating point, or throw an `Error` if the value
|
|
9
9
|
* cannot be casted. `null`, `undefined`, and `NaN` are considered valid inputs.
|
|
10
10
|
*
|
|
11
|
-
* @param {
|
|
12
|
-
* @return {
|
|
11
|
+
* @param {any} value
|
|
12
|
+
* @return {number}
|
|
13
13
|
* @throws {Error} if `value` does not represent a IEEE 754-2008 floating point. If casting from a string, see [BSON Double.fromString API documentation](https://mongodb.github.io/node-mongodb-native/Next/classes/BSON.Double.html#fromString)
|
|
14
14
|
* @api private
|
|
15
15
|
*/
|
package/lib/cast/int32.js
CHANGED
|
@@ -7,8 +7,8 @@ const assert = require('assert');
|
|
|
7
7
|
* Given a value, cast it to a Int32, or throw an `Error` if the value
|
|
8
8
|
* cannot be casted. `null` and `undefined` are considered valid.
|
|
9
9
|
*
|
|
10
|
-
* @param {
|
|
11
|
-
* @return {
|
|
10
|
+
* @param {any} value
|
|
11
|
+
* @return {number}
|
|
12
12
|
* @throws {Error} if `value` does not represent an integer, or is outside the bounds of an 32-bit integer.
|
|
13
13
|
* @api private
|
|
14
14
|
*/
|
package/lib/cast/number.js
CHANGED
|
@@ -6,8 +6,8 @@ const assert = require('assert');
|
|
|
6
6
|
* Given a value, cast it to a number, or throw an `Error` if the value
|
|
7
7
|
* cannot be casted. `null` and `undefined` are considered valid.
|
|
8
8
|
*
|
|
9
|
-
* @param {
|
|
10
|
-
* @return {
|
|
9
|
+
* @param {any} value
|
|
10
|
+
* @return {number}
|
|
11
11
|
* @throws {Error} if `value` is not one of the allowed values
|
|
12
12
|
* @api private
|
|
13
13
|
*/
|
package/lib/cast/string.js
CHANGED
|
@@ -6,8 +6,8 @@ const CastError = require('../error/cast');
|
|
|
6
6
|
* Given a value, cast it to a string, or throw a `CastError` if the value
|
|
7
7
|
* cannot be casted. `null` and `undefined` are considered valid.
|
|
8
8
|
*
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {
|
|
9
|
+
* @param {any} value
|
|
10
|
+
* @param {string} [path] optional the path to set on the CastError
|
|
11
11
|
* @return {string|null|undefined}
|
|
12
12
|
* @throws {CastError}
|
|
13
13
|
* @api private
|
package/lib/cast.js
CHANGED
|
@@ -24,12 +24,12 @@ const ALLOWED_GEOWITHIN_GEOJSON_TYPES = ['Polygon', 'MultiPolygon'];
|
|
|
24
24
|
* Handles internal casting for query filters.
|
|
25
25
|
*
|
|
26
26
|
* @param {Schema} schema
|
|
27
|
-
* @param {
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {
|
|
27
|
+
* @param {object} obj Object to cast
|
|
28
|
+
* @param {object} [options] the query options
|
|
29
|
+
* @param {boolean|"throw"} [options.strict] Whether to enable all strict options
|
|
30
|
+
* @param {boolean|"throw"} [options.strictQuery] Enable strict Queries
|
|
31
|
+
* @param {boolean} [options.sanitizeFilter] avoid adding implicit query selectors ($in)
|
|
32
|
+
* @param {boolean} [options.upsert]
|
|
33
33
|
* @param {Query} [context] passed to setters
|
|
34
34
|
* @api private
|
|
35
35
|
*/
|
package/lib/collection.js
CHANGED
|
@@ -13,9 +13,9 @@ const immediate = require('./helpers/immediate');
|
|
|
13
13
|
*
|
|
14
14
|
* This is the base class that drivers inherit from and implement.
|
|
15
15
|
*
|
|
16
|
-
* @param {
|
|
16
|
+
* @param {string} name name of the collection
|
|
17
17
|
* @param {Connection} conn A MongooseConnection instance
|
|
18
|
-
* @param {
|
|
18
|
+
* @param {object} [opts] optional collection options
|
|
19
19
|
* @api public
|
|
20
20
|
*/
|
|
21
21
|
|
|
@@ -87,7 +87,7 @@ Collection.prototype.onClose = function() {};
|
|
|
87
87
|
* Queues a method for later execution when its
|
|
88
88
|
* database connection opens.
|
|
89
89
|
*
|
|
90
|
-
* @param {
|
|
90
|
+
* @param {string} name name of the method to queue
|
|
91
91
|
* @param {Array} args arguments to pass to the method when executed
|
|
92
92
|
* @api private
|
|
93
93
|
*/
|
|
@@ -100,7 +100,7 @@ Collection.prototype.addQueue = function(name, args) {
|
|
|
100
100
|
/**
|
|
101
101
|
* Removes a queued method
|
|
102
102
|
*
|
|
103
|
-
* @param {
|
|
103
|
+
* @param {string} name name of the method to queue
|
|
104
104
|
* @param {Array} args arguments to pass to the method when executed
|
|
105
105
|
* @api private
|
|
106
106
|
*/
|