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.
Files changed (134) hide show
  1. package/lib/aggregate.js +68 -45
  2. package/lib/cast/bigint.js +2 -2
  3. package/lib/cast/boolean.js +3 -3
  4. package/lib/cast/double.js +2 -2
  5. package/lib/cast/int32.js +2 -2
  6. package/lib/cast/number.js +2 -2
  7. package/lib/cast/string.js +2 -2
  8. package/lib/cast.js +6 -6
  9. package/lib/collection.js +4 -4
  10. package/lib/connection.js +64 -78
  11. package/lib/cursor/aggregationCursor.js +8 -8
  12. package/lib/cursor/changeStream.js +55 -35
  13. package/lib/cursor/queryCursor.js +9 -9
  14. package/lib/document.js +394 -381
  15. package/lib/drivers/node-mongodb-native/collection.js +3 -3
  16. package/lib/drivers/node-mongodb-native/connection.js +8 -8
  17. package/lib/error/cast.js +2 -2
  18. package/lib/error/createCollectionsError.js +2 -2
  19. package/lib/error/divergentArray.js +1 -1
  20. package/lib/error/eachAsyncMultiError.js +1 -1
  21. package/lib/error/index.js +2 -2
  22. package/lib/error/invalidSchemaOption.js +1 -1
  23. package/lib/error/missingSchema.js +1 -1
  24. package/lib/error/objectParameter.js +3 -3
  25. package/lib/error/overwriteModel.js +1 -1
  26. package/lib/error/setOptionError.js +3 -3
  27. package/lib/error/strict.js +3 -3
  28. package/lib/error/strictPopulate.js +2 -2
  29. package/lib/error/syncIndexes.js +2 -2
  30. package/lib/error/validation.js +2 -2
  31. package/lib/error/validator.js +1 -1
  32. package/lib/error/version.js +2 -2
  33. package/lib/helpers/buildMiddlewareFilter.js +2 -2
  34. package/lib/helpers/clone.js +4 -4
  35. package/lib/helpers/createJSONSchemaTypeDefinition.js +4 -4
  36. package/lib/helpers/cursor/eachAsync.js +3 -3
  37. package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
  38. package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +3 -3
  39. package/lib/helpers/document/applyTimestamps.js +9 -9
  40. package/lib/helpers/document/applyVirtuals.js +6 -6
  41. package/lib/helpers/document/compile.js +10 -10
  42. package/lib/helpers/document/getDeepestSubdocumentForPath.js +2 -2
  43. package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
  44. package/lib/helpers/indexes/isIndexEqual.js +3 -3
  45. package/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
  46. package/lib/helpers/isMongooseObject.js +1 -1
  47. package/lib/helpers/isObject.js +2 -2
  48. package/lib/helpers/isSimpleValidator.js +2 -2
  49. package/lib/helpers/minimize.js +2 -2
  50. package/lib/helpers/model/applyHooks.js +1 -1
  51. package/lib/helpers/model/castBulkWrite.js +2 -2
  52. package/lib/helpers/pluralize.js +1 -1
  53. package/lib/helpers/populate/assignRawDocsToIdStructure.js +2 -2
  54. package/lib/helpers/populate/assignVals.js +6 -6
  55. package/lib/helpers/populate/createPopulateQueryFilter.js +2 -2
  56. package/lib/helpers/populate/getModelsMapForPopulate.js +12 -12
  57. package/lib/helpers/populate/getSchemaTypes.js +1 -1
  58. package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
  59. package/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
  60. package/lib/helpers/projection/hasIncludedChildren.js +1 -1
  61. package/lib/helpers/projection/isPathExcluded.js +3 -3
  62. package/lib/helpers/projection/isSubpath.js +1 -1
  63. package/lib/helpers/query/castUpdate.js +14 -14
  64. package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +5 -5
  65. package/lib/helpers/query/handleImmutable.js +6 -6
  66. package/lib/helpers/schema/getIndexes.js +1 -1
  67. package/lib/helpers/schema/getSubdocumentStrictValue.js +1 -1
  68. package/lib/helpers/setDefaultsOnInsert.js +10 -8
  69. package/lib/helpers/update/modifiedPaths.js +2 -2
  70. package/lib/helpers/update/removeUnusedArrayFilters.js +7 -2
  71. package/lib/helpers/updateValidators.js +3 -10
  72. package/lib/model.js +323 -298
  73. package/lib/mongoose.js +55 -57
  74. package/lib/options/schemaArrayOptions.js +2 -2
  75. package/lib/options/schemaBufferOptions.js +1 -1
  76. package/lib/options/schemaDocumentArrayOptions.js +23 -0
  77. package/lib/options/schemaNumberOptions.js +3 -3
  78. package/lib/options/schemaObjectIdOptions.js +2 -2
  79. package/lib/options/schemaStringOptions.js +6 -6
  80. package/lib/options/schemaSubdocumentOptions.js +23 -0
  81. package/lib/options/schemaTypeOptions.js +13 -13
  82. package/lib/options/virtualOptions.js +11 -11
  83. package/lib/plugins/index.js +0 -1
  84. package/lib/query.js +349 -310
  85. package/lib/queryHelpers.js +4 -4
  86. package/lib/schema/array.js +18 -18
  87. package/lib/schema/bigint.js +13 -13
  88. package/lib/schema/boolean.js +13 -13
  89. package/lib/schema/buffer.js +15 -15
  90. package/lib/schema/date.js +16 -16
  91. package/lib/schema/decimal128.js +13 -13
  92. package/lib/schema/documentArray.js +16 -16
  93. package/lib/schema/documentArrayElement.js +5 -6
  94. package/lib/schema/double.js +12 -12
  95. package/lib/schema/int32.js +13 -13
  96. package/lib/schema/map.js +10 -10
  97. package/lib/schema/mixed.js +10 -10
  98. package/lib/schema/number.js +18 -18
  99. package/lib/schema/objectId.js +14 -14
  100. package/lib/schema/operators/text.js +3 -3
  101. package/lib/schema/string.js +17 -17
  102. package/lib/schema/subdocument.js +13 -13
  103. package/lib/schema/union.js +3 -3
  104. package/lib/schema/uuid.js +16 -16
  105. package/lib/schema.js +77 -77
  106. package/lib/schemaType.js +76 -68
  107. package/lib/stateMachine.js +5 -8
  108. package/lib/types/array/index.js +1 -1
  109. package/lib/types/array/methods/index.js +12 -12
  110. package/lib/types/arraySubdocument.js +8 -8
  111. package/lib/types/buffer.js +4 -4
  112. package/lib/types/documentArray/index.js +1 -1
  113. package/lib/types/documentArray/methods/index.js +5 -5
  114. package/lib/types/map.js +3 -3
  115. package/lib/types/subdocument.js +11 -11
  116. package/lib/utils.js +45 -45
  117. package/lib/virtualType.js +18 -18
  118. package/package.json +11 -7
  119. package/types/aggregate.d.ts +3 -0
  120. package/types/connection.d.ts +2 -2
  121. package/types/cursor.d.ts +1 -1
  122. package/types/document.d.ts +4 -4
  123. package/types/index.d.ts +17 -16
  124. package/types/indexes.d.ts +1 -1
  125. package/types/inferhydrateddoctype.d.ts +23 -3
  126. package/types/inferrawdoctype.d.ts +32 -10
  127. package/types/inferschematype.d.ts +41 -4
  128. package/types/models.d.ts +7 -4
  129. package/types/pipelinestage.d.ts +3 -2
  130. package/types/query.d.ts +2 -2
  131. package/types/schemaoptions.d.ts +1 -1
  132. package/types/schematypes.d.ts +3 -0
  133. package/types/virtuals.d.ts +10 -10
  134. package/lib/plugins/validateBeforeSave.js +0 -47
package/lib/query.js CHANGED
@@ -101,10 +101,10 @@ const opToThunk = new Map([
101
101
  * // this unless you're an advanced user with a very good reason to.
102
102
  * const query = new mongoose.Query();
103
103
  *
104
- * @param {Object} [options]
105
- * @param {Object} [model]
106
- * @param {Object} [conditions]
107
- * @param {Object} [collection] Mongoose collection
104
+ * @param {object} [options]
105
+ * @param {object} [model]
106
+ * @param {object} [conditions]
107
+ * @param {object} [collection] Mongoose collection
108
108
  * @api public
109
109
  */
110
110
 
@@ -379,7 +379,7 @@ Query.prototype.clone = function() {
379
379
  *
380
380
  * @see $where https://www.mongodb.com/docs/manual/reference/operator/where/
381
381
  * @method $where
382
- * @param {String|Function} js javascript string or function
382
+ * @param {string|Function} js javascript string or function
383
383
  * @return {Query} this
384
384
  * @memberOf Query
385
385
  * @instance
@@ -411,7 +411,7 @@ Query.prototype.clone = function() {
411
411
  * @method where
412
412
  * @memberOf Query
413
413
  * @instance
414
- * @param {String|Object} [path]
414
+ * @param {string|object} [path]
415
415
  * @param {any} [val]
416
416
  * @return {Query} this
417
417
  * @api public
@@ -447,8 +447,8 @@ Query.prototype.clone = function() {
447
447
  * @method slice
448
448
  * @memberOf Query
449
449
  * @instance
450
- * @param {String} [path]
451
- * @param {Number|Array} val number of elements to slice or array with number of elements to skip and number of elements to slice
450
+ * @param {string} [path]
451
+ * @param {number|Array} val number of elements to slice or array with number of elements to skip and number of elements to slice
452
452
  * @return {Query} this
453
453
  * @see mongodb https://www.mongodb.com/docs/manual/tutorial/query-documents/#projection
454
454
  * @see $slice https://www.mongodb.com/docs/manual/reference/projection/slice/#prj._S_slice
@@ -529,7 +529,7 @@ Query.prototype._validateOp = function() {
529
529
  * @method equals
530
530
  * @memberOf Query
531
531
  * @instance
532
- * @param {Object} val
532
+ * @param {object} val
533
533
  * @return {Query} this
534
534
  * @api public
535
535
  */
@@ -597,8 +597,8 @@ Query.prototype._validateOp = function() {
597
597
  * @method gt
598
598
  * @memberOf Query
599
599
  * @instance
600
- * @param {String} [path]
601
- * @param {Number} val
600
+ * @param {string} [path]
601
+ * @param {number} val
602
602
  * @see $gt https://www.mongodb.com/docs/manual/reference/operator/gt/
603
603
  * @api public
604
604
  */
@@ -611,8 +611,8 @@ Query.prototype._validateOp = function() {
611
611
  * @method gte
612
612
  * @memberOf Query
613
613
  * @instance
614
- * @param {String} [path]
615
- * @param {Number} val
614
+ * @param {string} [path]
615
+ * @param {number} val
616
616
  * @see $gte https://www.mongodb.com/docs/manual/reference/operator/gte/
617
617
  * @api public
618
618
  */
@@ -625,8 +625,8 @@ Query.prototype._validateOp = function() {
625
625
  * @method lt
626
626
  * @memberOf Query
627
627
  * @instance
628
- * @param {String} [path]
629
- * @param {Number} val
628
+ * @param {string} [path]
629
+ * @param {number} val
630
630
  * @see $lt https://www.mongodb.com/docs/manual/reference/operator/lt/
631
631
  * @api public
632
632
  */
@@ -640,8 +640,8 @@ Query.prototype._validateOp = function() {
640
640
  * @see $lte https://www.mongodb.com/docs/manual/reference/operator/lte/
641
641
  * @memberOf Query
642
642
  * @instance
643
- * @param {String} [path]
644
- * @param {Number} val
643
+ * @param {string} [path]
644
+ * @param {number} val
645
645
  * @api public
646
646
  */
647
647
 
@@ -654,7 +654,7 @@ Query.prototype._validateOp = function() {
654
654
  * @method ne
655
655
  * @memberOf Query
656
656
  * @instance
657
- * @param {String} [path]
657
+ * @param {string} [path]
658
658
  * @param {any} val
659
659
  * @api public
660
660
  */
@@ -668,7 +668,7 @@ Query.prototype._validateOp = function() {
668
668
  * @method in
669
669
  * @memberOf Query
670
670
  * @instance
671
- * @param {String} [path]
671
+ * @param {string} [path]
672
672
  * @param {Array} val
673
673
  * @api public
674
674
  */
@@ -682,7 +682,7 @@ Query.prototype._validateOp = function() {
682
682
  * @method nin
683
683
  * @memberOf Query
684
684
  * @instance
685
- * @param {String} [path]
685
+ * @param {string} [path]
686
686
  * @param {Array} val
687
687
  * @api public
688
688
  */
@@ -702,7 +702,7 @@ Query.prototype._validateOp = function() {
702
702
  * @method all
703
703
  * @memberOf Query
704
704
  * @instance
705
- * @param {String} [path]
705
+ * @param {string} [path]
706
706
  * @param {Array} val
707
707
  * @api public
708
708
  */
@@ -722,8 +722,8 @@ Query.prototype._validateOp = function() {
722
722
  * @method size
723
723
  * @memberOf Query
724
724
  * @instance
725
- * @param {String} [path]
726
- * @param {Number} val
725
+ * @param {string} [path]
726
+ * @param {number} val
727
727
  * @api public
728
728
  */
729
729
 
@@ -736,8 +736,8 @@ Query.prototype._validateOp = function() {
736
736
  * @method regex
737
737
  * @memberOf Query
738
738
  * @instance
739
- * @param {String} [path]
740
- * @param {String|RegExp} val
739
+ * @param {string} [path]
740
+ * @param {string|RegExp} val
741
741
  * @api public
742
742
  */
743
743
 
@@ -750,8 +750,8 @@ Query.prototype._validateOp = function() {
750
750
  * @method maxDistance
751
751
  * @memberOf Query
752
752
  * @instance
753
- * @param {String} [path]
754
- * @param {Number} val
753
+ * @param {string} [path]
754
+ * @param {number} val
755
755
  * @api public
756
756
  */
757
757
 
@@ -770,7 +770,7 @@ Query.prototype._validateOp = function() {
770
770
  * @method mod
771
771
  * @memberOf Query
772
772
  * @instance
773
- * @param {String} [path]
773
+ * @param {string} [path]
774
774
  * @param {Array} val must be of length 2, first element is `divisor`, 2nd element is `remainder`.
775
775
  * @return {Query} this
776
776
  * @see $mod https://www.mongodb.com/docs/manual/reference/operator/mod/
@@ -819,8 +819,8 @@ Query.prototype.mod = function() {
819
819
  * @method exists
820
820
  * @memberOf Query
821
821
  * @instance
822
- * @param {String} [path]
823
- * @param {Boolean} val
822
+ * @param {string} [path]
823
+ * @param {boolean} val
824
824
  * @return {Query} this
825
825
  * @see $exists https://www.mongodb.com/docs/manual/reference/operator/exists/
826
826
  * @api public
@@ -848,8 +848,8 @@ Query.prototype.mod = function() {
848
848
  * @method elemMatch
849
849
  * @memberOf Query
850
850
  * @instance
851
- * @param {String|Object|Function} path
852
- * @param {Object|Function} filter
851
+ * @param {string|object|Function} path
852
+ * @param {object|Function} filter
853
853
  * @return {Query} this
854
854
  * @see $elemMatch https://www.mongodb.com/docs/manual/reference/operator/elemMatch/
855
855
  * @api public
@@ -908,7 +908,7 @@ Query.prototype.mod = function() {
908
908
  * @method limit
909
909
  * @memberOf Query
910
910
  * @instance
911
- * @param {Number} val
911
+ * @param {number} val
912
912
  * @api public
913
913
  */
914
914
 
@@ -941,7 +941,7 @@ Query.prototype.limit = function limit(v) {
941
941
  * @method skip
942
942
  * @memberOf Query
943
943
  * @instance
944
- * @param {Number} val
944
+ * @param {number} val
945
945
  * @see cursor.skip https://www.mongodb.com/docs/manual/reference/method/cursor.skip/
946
946
  * @api public
947
947
  */
@@ -975,7 +975,7 @@ Query.prototype.skip = function skip(v) {
975
975
  * @method batchSize
976
976
  * @memberOf Query
977
977
  * @instance
978
- * @param {Number} val
978
+ * @param {number} val
979
979
  * @see batchSize https://www.mongodb.com/docs/manual/reference/method/cursor.batchSize/
980
980
  * @api public
981
981
  */
@@ -994,7 +994,7 @@ Query.prototype.skip = function skip(v) {
994
994
  * @method comment
995
995
  * @memberOf Query
996
996
  * @instance
997
- * @param {String} val
997
+ * @param {string} val
998
998
  * @see comment https://www.mongodb.com/docs/manual/reference/operator/comment/
999
999
  * @api public
1000
1000
  */
@@ -1013,7 +1013,7 @@ Query.prototype.skip = function skip(v) {
1013
1013
  * @method hint
1014
1014
  * @memberOf Query
1015
1015
  * @instance
1016
- * @param {Object} val a hint object
1016
+ * @param {object} val a hint object
1017
1017
  * @return {Query} this
1018
1018
  * @see $hint https://www.mongodb.com/docs/manual/reference/operator/hint/
1019
1019
  * @api public
@@ -1044,8 +1044,8 @@ Query.prototype.skip = function skip(v) {
1044
1044
  * @method projection
1045
1045
  * @memberOf Query
1046
1046
  * @instance
1047
- * @param {Object|null} arg
1048
- * @return {Object} the current projection
1047
+ * @param {object|null} arg
1048
+ * @return {object} the current projection
1049
1049
  * @api public
1050
1050
  */
1051
1051
 
@@ -1102,7 +1102,7 @@ Query.prototype.projection = function(arg) {
1102
1102
  * @method select
1103
1103
  * @memberOf Query
1104
1104
  * @instance
1105
- * @param {Object|String|String[]} arg
1105
+ * @param {object|string|Array<string>} arg
1106
1106
  * @return {Query} this
1107
1107
  * @see SchemaType https://mongoosejs.com/docs/api/schematype.html
1108
1108
  * @api public
@@ -1206,7 +1206,7 @@ Query.prototype.select = function select() {
1206
1206
  * @method schemaLevelProjections
1207
1207
  * @memberOf Query
1208
1208
  * @instance
1209
- * @param {Boolean} value
1209
+ * @param {boolean} value
1210
1210
  * @return {Query} this
1211
1211
  * @see SchemaTypeOptions https://mongoosejs.com/docs/schematypes.html#all-schema-types
1212
1212
  * @api public
@@ -1259,7 +1259,7 @@ Query.prototype.schemaLevelProjections = function schemaLevelProjections(value)
1259
1259
  * @method sanitizeProjection
1260
1260
  * @memberOf Query
1261
1261
  * @instance
1262
- * @param {Boolean} value
1262
+ * @param {boolean} value
1263
1263
  * @return {Query} this
1264
1264
  * @see sanitizeProjection https://thecodebarbarian.com/whats-new-in-mongoose-5-13-sanitizeprojection.html
1265
1265
  * @api public
@@ -1319,7 +1319,7 @@ Query.prototype.sanitizeProjection = function sanitizeProjection(value) {
1319
1319
  * @method read
1320
1320
  * @memberOf Query
1321
1321
  * @instance
1322
- * @param {String} mode one of the listed preference options or aliases
1322
+ * @param {string} mode one of the listed preference options or aliases
1323
1323
  * @param {Array} [tags] optional tags for this query
1324
1324
  * @see mongodb https://www.mongodb.com/docs/manual/applications/replication/#read-preference
1325
1325
  * @return {Query} this
@@ -1432,8 +1432,8 @@ Query.prototype.session = function session(v) {
1432
1432
  * @method writeConcern
1433
1433
  * @memberOf Query
1434
1434
  * @instance
1435
- * @param {Object} writeConcern the write concern value to set
1436
- * @see WriteConcernSettings https://mongodb.github.io/node-mongodb-native/4.9/interfaces/WriteConcernSettings.html
1435
+ * @param {object} writeConcern the write concern value to set
1436
+ * @see WriteConcernSettings https://mongodb.github.io/node-mongodb-native/7.0/interfaces/WriteConcernSettings.html
1437
1437
  * @return {Query} this
1438
1438
  * @api public
1439
1439
  */
@@ -1473,7 +1473,7 @@ Query.prototype.writeConcern = function writeConcern(val) {
1473
1473
  * @method w
1474
1474
  * @memberOf Query
1475
1475
  * @instance
1476
- * @param {String|number} val 0 for fire-and-forget, 1 for acknowledged by one server, 'majority' for majority of the replica set, or [any of the more advanced options](https://www.mongodb.com/docs/manual/reference/write-concern/#w-option).
1476
+ * @param {string|number} val 0 for fire-and-forget, 1 for acknowledged by one server, 'majority' for majority of the replica set, or [any of the more advanced options](https://www.mongodb.com/docs/manual/reference/write-concern/#w-option).
1477
1477
  * @see mongodb https://www.mongodb.com/docs/manual/reference/write-concern/#w-option
1478
1478
  * @return {Query} this
1479
1479
  * @api public
@@ -1640,7 +1640,7 @@ Query.prototype.wtimeout = function wtimeout(ms) {
1640
1640
  * query.setOptions({ maxTimeMS: 1000 });
1641
1641
  * query.getOptions(); // { limit: 10, maxTimeMS: 1000 }
1642
1642
  *
1643
- * @return {Object} the options
1643
+ * @return {object} the options
1644
1644
  * @api public
1645
1645
  */
1646
1646
 
@@ -1700,7 +1700,7 @@ Query.prototype.getOptions = function() {
1700
1700
  * - [explain](https://www.mongodb.com/docs/manual/reference/method/cursor.explain/)
1701
1701
  * - [middleware](https://mongoosejs.com/docs/middleware.html#skipping): set to `false` to skip all user-defined middleware, or `{ pre: false }` / `{ post: false }` to skip only pre or post hooks
1702
1702
  *
1703
- * @param {Object} options
1703
+ * @param {object} options
1704
1704
  * @return {Query} this
1705
1705
  * @api public
1706
1706
  */
@@ -1860,7 +1860,7 @@ Query.prototype.explain = function explain(verbose) {
1860
1860
  * // Equivalent:
1861
1861
  * await query.find().sort({ name: 1 }).allowDiskUse();
1862
1862
  *
1863
- * @param {Boolean} [v] Enable/disable `allowDiskUse`. If called with 0 arguments, sets `allowDiskUse: true`
1863
+ * @param {boolean} [v] Enable/disable `allowDiskUse`. If called with 0 arguments, sets `allowDiskUse: true`
1864
1864
  * @return {Query} this
1865
1865
  * @api public
1866
1866
  */
@@ -1890,7 +1890,7 @@ Query.prototype.allowDiskUse = function(v) {
1890
1890
  * // >= 1 doc in the queried collection
1891
1891
  * const res = await query.find({ $where: 'sleep(1000) || true' }).maxTimeMS(100);
1892
1892
  *
1893
- * @param {Number} [ms] The number of milliseconds
1893
+ * @param {number} [ms] The number of milliseconds
1894
1894
  * @return {Query} this
1895
1895
  * @api public
1896
1896
  */
@@ -1909,7 +1909,7 @@ Query.prototype.maxTimeMS = function(ms) {
1909
1909
  * query.find({ a: 1 }).where('b').gt(2);
1910
1910
  * query.getFilter(); // { a: 1, b: { $gt: 2 } }
1911
1911
  *
1912
- * @return {Object} current query filter
1912
+ * @return {object} current query filter
1913
1913
  * @api public
1914
1914
  */
1915
1915
 
@@ -1929,7 +1929,7 @@ Query.prototype.getFilter = function() {
1929
1929
  * query.find({ a: 1 }).where('b').gt(2);
1930
1930
  * query.getQuery(); // { a: 1, b: { $gt: 2 } }
1931
1931
  *
1932
- * @return {Object} current query filter
1932
+ * @return {object} current query filter
1933
1933
  * @api public
1934
1934
  */
1935
1935
 
@@ -1947,7 +1947,7 @@ Query.prototype.getQuery = function() {
1947
1947
  * query.setQuery({ a: 2 });
1948
1948
  * query.getQuery(); // { a: 2 }
1949
1949
  *
1950
- * @param {Object} new query conditions
1950
+ * @param {object} new query conditions
1951
1951
  * @return {undefined}
1952
1952
  * @api public
1953
1953
  */
@@ -1965,7 +1965,7 @@ Query.prototype.setQuery = function(val) {
1965
1965
  * query.updateOne({}, { $set: { a: 5 } });
1966
1966
  * query.getUpdate(); // { $set: { a: 5 } }
1967
1967
  *
1968
- * @return {Object} current update operations
1968
+ * @return {object} current update operations
1969
1969
  * @api public
1970
1970
  */
1971
1971
 
@@ -1983,20 +1983,20 @@ Query.prototype.getUpdate = function() {
1983
1983
  * query.setUpdate({ $set: { b: 6 } });
1984
1984
  * query.getUpdate(); // { $set: { b: 6 } }
1985
1985
  *
1986
- * @param {Object} new update operation
1986
+ * @param {object} new update operation
1987
1987
  * @return {undefined}
1988
1988
  * @api public
1989
1989
  */
1990
1990
 
1991
1991
  Query.prototype.setUpdate = function(val) {
1992
- this._update = val;
1992
+ this._update = clone(val);
1993
1993
  };
1994
1994
 
1995
1995
  /**
1996
1996
  * Returns fields selection for this query.
1997
1997
  *
1998
1998
  * @method _fieldsForExec
1999
- * @return {Object}
1999
+ * @return {object}
2000
2000
  * @api private
2001
2001
  * @memberOf Query
2002
2002
  */
@@ -2016,7 +2016,7 @@ Query.prototype._fieldsForExec = function() {
2016
2016
  * Return an update document with corrected `$set` operations.
2017
2017
  *
2018
2018
  * @method _updateForExec
2019
- * @return {Object}
2019
+ * @return {object}
2020
2020
  * @api private
2021
2021
  * @memberOf Query
2022
2022
  */
@@ -2063,7 +2063,7 @@ Query.prototype._updateForExec = function() {
2063
2063
  * This method is inherited by `mquery`
2064
2064
  *
2065
2065
  * @method _ensurePath
2066
- * @param {String} method
2066
+ * @param {string} method
2067
2067
  * @api private
2068
2068
  * @memberOf Query
2069
2069
  */
@@ -2074,8 +2074,8 @@ Query.prototype._updateForExec = function() {
2074
2074
  * @method canMerge
2075
2075
  * @memberOf Query
2076
2076
  * @instance
2077
- * @param {Object} conds
2078
- * @return {Boolean}
2077
+ * @param {object} conds
2078
+ * @return {boolean}
2079
2079
  * @api private
2080
2080
  */
2081
2081
 
@@ -2188,7 +2188,7 @@ Query.prototype._optionsForExec = function(model) {
2188
2188
  * - [mongoose-lean-getters](https://plugins.mongoosejs.io/plugins/lean-getters)
2189
2189
  * - [mongoose-lean-defaults](https://www.npmjs.com/package/mongoose-lean-defaults)
2190
2190
  *
2191
- * @param {Boolean|Object} bool defaults to true
2191
+ * @param {boolean|object} bool defaults to true
2192
2192
  * @return {Query} this
2193
2193
  * @api public
2194
2194
  */
@@ -2209,8 +2209,8 @@ Query.prototype.lean = function(v) {
2209
2209
  * new Query().updateOne({}, {}).set('updatedAt', new Date());
2210
2210
  * new Query().updateMany({}, {}).set({ updatedAt: new Date() });
2211
2211
  *
2212
- * @param {String|Object} path path or object of key/value pairs to set
2213
- * @param {Any} [val] the value to set
2212
+ * @param {string|object} path path or object of key/value pairs to set
2213
+ * @param {any} [val] the value to set
2214
2214
  * @return {Query} this
2215
2215
  * @api public
2216
2216
  */
@@ -2243,7 +2243,7 @@ Query.prototype.set = function(path, val) {
2243
2243
  * const query = Model.updateOne({}, { $set: { name: 'Jean-Luc Picard' } });
2244
2244
  * query.get('name'); // 'Jean-Luc Picard'
2245
2245
  *
2246
- * @param {String|Object} path path or object of key/value pairs to get
2246
+ * @param {string|object} path path or object of key/value pairs to get
2247
2247
  * @return {Query} this
2248
2248
  * @api public
2249
2249
  */
@@ -2338,8 +2338,8 @@ Query.prototype._unsetCastError = function _unsetCastError() {
2338
2338
  * Mongoose sends `Query.prototype.options` to the MongoDB server, and the
2339
2339
  * above options are not relevant for the MongoDB server.
2340
2340
  *
2341
- * @param {Object} options if specified, overwrites the current options
2342
- * @return {Object} the options
2341
+ * @param {object} options if specified, overwrites the current options
2342
+ * @return {object} the options
2343
2343
  * @api public
2344
2344
  */
2345
2345
 
@@ -2482,7 +2482,7 @@ Query.prototype._find = async function _find() {
2482
2482
  *
2483
2483
  * const arr = await Movie.find({ year: { $gte: 1980, $lte: 1989 } });
2484
2484
  *
2485
- * @param {Object|ObjectId} [filter] mongodb filter. If not specified, returns all documents.
2485
+ * @param {object|ObjectId} [filter] mongodb filter. If not specified, returns all documents.
2486
2486
  * @return {Query} this
2487
2487
  * @api public
2488
2488
  */
@@ -2511,7 +2511,7 @@ Query.prototype.find = function(conditions) {
2511
2511
  *
2512
2512
  * When a Query is passed, conditions, field selection and options are merged.
2513
2513
  *
2514
- * @param {Query|Object} source
2514
+ * @param {Query|object} source
2515
2515
  * @return {Query} this
2516
2516
  */
2517
2517
 
@@ -2602,7 +2602,7 @@ Query.prototype.merge = function(source) {
2602
2602
  /**
2603
2603
  * Adds a collation to this op (MongoDB 3.4 and up)
2604
2604
  *
2605
- * @param {Object} value
2605
+ * @param {object} value
2606
2606
  * @return {Query} this
2607
2607
  * @see MongoDB docs https://www.mongodb.com/docs/manual/reference/method/cursor.collation/#cursor.collation
2608
2608
  * @api public
@@ -2679,9 +2679,9 @@ Query.prototype._completeOne = function(doc, res, projection, callback) {
2679
2679
  * of the model. Used to initialize docs returned from the db from `find()`
2680
2680
  *
2681
2681
  * @param {Array} docs
2682
- * @param {Object} fields the projection used, including `select` from schemas
2683
- * @param {Object} userProvidedFields the user-specified projection
2684
- * @param {Object} [opts]
2682
+ * @param {object} fields the projection used, including `select` from schemas
2683
+ * @param {object} userProvidedFields the user-specified projection
2684
+ * @param {object} [opts]
2685
2685
  * @param {Array} [opts.populated]
2686
2686
  * @param {ClientSession} [opts.session]
2687
2687
  * @api private
@@ -2758,10 +2758,10 @@ Query.prototype._findOne = async function _findOne() {
2758
2758
  * const query = Kitten.where({ color: 'white' });
2759
2759
  * const kitten = await query.findOne();
2760
2760
  *
2761
- * @param {Object} [filter] mongodb selector
2762
- * @param {Object} [projection] optional fields to return
2763
- * @param {Object} [options] see [`setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
2764
- * @param {Boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
2761
+ * @param {object} [filter] mongodb selector
2762
+ * @param {object} [projection] optional fields to return
2763
+ * @param {object} [options] see [`setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
2764
+ * @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
2765
2765
  * @return {Query} this
2766
2766
  * @see findOne https://www.mongodb.com/docs/manual/reference/method/db.collection.findOne/
2767
2767
  * @see Query.select https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
@@ -2801,7 +2801,7 @@ Query.prototype.findOne = function(conditions, projection, options) {
2801
2801
  /**
2802
2802
  * Execute a countDocuments query
2803
2803
  *
2804
- * @see countDocuments https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#countDocuments
2804
+ * @see countDocuments https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#countDocuments
2805
2805
  * @api private
2806
2806
  */
2807
2807
 
@@ -2861,7 +2861,7 @@ Query.prototype._applyTranslateAliases = function _applyTranslateAliases() {
2861
2861
  /**
2862
2862
  * Execute a estimatedDocumentCount() query
2863
2863
  *
2864
- * @see estimatedDocumentCount https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#estimatedDocumentCount
2864
+ * @see estimatedDocumentCount https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#estimatedDocumentCount
2865
2865
  * @api private
2866
2866
  */
2867
2867
 
@@ -2892,9 +2892,9 @@ Query.prototype._estimatedDocumentCount = async function _estimatedDocumentCount
2892
2892
  *
2893
2893
  * await Model.find().estimatedDocumentCount();
2894
2894
  *
2895
- * @param {Object} [options] passed transparently to the [MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/EstimatedDocumentCountOptions.html)
2895
+ * @param {object} [options] passed transparently to the [MongoDB driver](https://mongodb.github.io/node-mongodb-native/7.0/interfaces/EstimatedDocumentCountOptions.html)
2896
2896
  * @return {Query} this
2897
- * @see estimatedDocumentCount https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#estimatedDocumentCount
2897
+ * @see estimatedDocumentCount https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#estimatedDocumentCount
2898
2898
  * @api public
2899
2899
  */
2900
2900
 
@@ -2918,7 +2918,7 @@ Query.prototype.estimatedDocumentCount = function(options) {
2918
2918
  * except it always does a full collection scan when passed an empty filter `{}`.
2919
2919
  *
2920
2920
  * There are also minor differences in how `countDocuments()` handles
2921
- * [`$where` and a couple geospatial operators](https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#countDocuments).
2921
+ * [`$where` and a couple geospatial operators](https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#countDocuments).
2922
2922
  * versus `count()`.
2923
2923
  *
2924
2924
  * This function triggers the following middleware.
@@ -2936,7 +2936,7 @@ Query.prototype.estimatedDocumentCount = function(options) {
2936
2936
  * query.where('color', 'black').countDocuments().exec();
2937
2937
  *
2938
2938
  * The `countDocuments()` function is similar to `count()`, but there are a
2939
- * [few operators that `countDocuments()` does not support](https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#countDocuments).
2939
+ * [few operators that `countDocuments()` does not support](https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#countDocuments).
2940
2940
  * Below are the operators that `count()` supports but `countDocuments()` does not,
2941
2941
  * and the suggested replacement:
2942
2942
  *
@@ -2944,10 +2944,10 @@ Query.prototype.estimatedDocumentCount = function(options) {
2944
2944
  * - `$near`: [`$geoWithin`](https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/) with [`$center`](https://www.mongodb.com/docs/manual/reference/operator/query/center/#op._S_center)
2945
2945
  * - `$nearSphere`: [`$geoWithin`](https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/) with [`$centerSphere`](https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op._S_centerSphere)
2946
2946
  *
2947
- * @param {Object} [filter] mongodb selector
2948
- * @param {Object} [options]
2947
+ * @param {object} [filter] mongodb selector
2948
+ * @param {object} [options]
2949
2949
  * @return {Query} this
2950
- * @see countDocuments https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#countDocuments
2950
+ * @see countDocuments https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#countDocuments
2951
2951
  * @api public
2952
2952
  */
2953
2953
 
@@ -3009,9 +3009,9 @@ Query.prototype.__distinct = async function __distinct() {
3009
3009
  * distinct(field)
3010
3010
  * distinct()
3011
3011
  *
3012
- * @param {String} [field]
3013
- * @param {Object|Query} [filter]
3014
- * @param {Object} [options]
3012
+ * @param {string} [field]
3013
+ * @param {object|Query} [filter]
3014
+ * @param {object} [options]
3015
3015
  * @return {Query} this
3016
3016
  * @see distinct https://www.mongodb.com/docs/manual/reference/method/db.collection.distinct/
3017
3017
  * @api public
@@ -3070,9 +3070,9 @@ Query.prototype.distinct = function(field, conditions, options) {
3070
3070
  *
3071
3071
  * Cannot be used with `distinct()`
3072
3072
  *
3073
- * @param {Object|String|Array<Array<(string | number)>>} arg
3074
- * @param {Object} [options]
3075
- * @param {Boolean} [options.override=false] If true, replace existing sort options with `arg`
3073
+ * @param {object|string|Array<Array<(string | number)>>} arg
3074
+ * @param {object} [options]
3075
+ * @param {boolean} [options.override=false] If true, replace existing sort options with `arg`
3076
3076
  * @return {Query} this
3077
3077
  * @see cursor.sort https://www.mongodb.com/docs/manual/reference/method/cursor.sort/
3078
3078
  * @api public
@@ -3166,7 +3166,7 @@ function _handleSortValue(val, key) {
3166
3166
  *
3167
3167
  * await Character.deleteOne({ name: 'Eddard Stark' });
3168
3168
  *
3169
- * This function calls the MongoDB driver's [`Collection#deleteOne()` function](https://mongodb.github.io/node-mongodb-native/6.15/classes/Collection.html#deleteOne).
3169
+ * This function calls the MongoDB driver's [`Collection#deleteOne()` function](https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#deleteOne).
3170
3170
  * The returned [promise](https://mongoosejs.com/docs/queries.html) resolves to an
3171
3171
  * object that contains 2 properties:
3172
3172
  *
@@ -3179,12 +3179,12 @@ function _handleSortValue(val, key) {
3179
3179
  * // `1` if MongoDB deleted a doc, `0` if no docs matched the filter `{ name: ... }`
3180
3180
  * res.deletedCount;
3181
3181
  *
3182
- * @param {Object|Query} [filter] mongodb selector
3183
- * @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
3184
- * @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3182
+ * @param {object|Query} [filter] mongodb selector
3183
+ * @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
3184
+ * @param {boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3185
3185
  * @return {Query} this
3186
- * @see DeleteResult https://mongodb.github.io/node-mongodb-native/6.15/interfaces/DeleteResult.html
3187
- * @see deleteOne https://mongodb.github.io/node-mongodb-native/6.15/classes/Collection.html#deleteOne
3186
+ * @see DeleteResult https://mongodb.github.io/node-mongodb-native/7.0/interfaces/DeleteResult.html
3187
+ * @see deleteOne https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#deleteOne
3188
3188
  * @api public
3189
3189
  */
3190
3190
 
@@ -3242,7 +3242,7 @@ Query.prototype._deleteOne = async function _deleteOne() {
3242
3242
  *
3243
3243
  * await Character.deleteMany({ name: /Stark/, age: { $gte: 18 } });
3244
3244
  *
3245
- * This function calls the MongoDB driver's [`Collection#deleteMany()` function](https://mongodb.github.io/node-mongodb-native/6.15/classes/Collection.html#deleteMany).
3245
+ * This function calls the MongoDB driver's [`Collection#deleteMany()` function](https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#deleteMany).
3246
3246
  * The returned [promise](https://mongoosejs.com/docs/queries.html) resolves to an
3247
3247
  * object that contains 2 properties:
3248
3248
  *
@@ -3255,12 +3255,12 @@ Query.prototype._deleteOne = async function _deleteOne() {
3255
3255
  * // `0` if no docs matched the filter, number of docs deleted otherwise
3256
3256
  * res.deletedCount;
3257
3257
  *
3258
- * @param {Object|Query} [filter] mongodb selector
3259
- * @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
3260
- * @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3258
+ * @param {object|Query} [filter] mongodb selector
3259
+ * @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
3260
+ * @param {boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3261
3261
  * @return {Query} this
3262
- * @see DeleteResult https://mongodb.github.io/node-mongodb-native/6.15/interfaces/DeleteResult.html
3263
- * @see deleteMany https://mongodb.github.io/node-mongodb-native/6.15/classes/Collection.html#deleteMany
3262
+ * @see DeleteResult https://mongodb.github.io/node-mongodb-native/7.0/interfaces/DeleteResult.html
3263
+ * @see deleteMany https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#deleteMany
3264
3264
  * @api public
3265
3265
  */
3266
3266
 
@@ -3312,8 +3312,8 @@ Query.prototype._deleteMany = async function _deleteMany() {
3312
3312
  *
3313
3313
  * @param {Model} model
3314
3314
  * @param {Document} doc
3315
- * @param {Object} res 3rd parameter to callback
3316
- * @param {Object} fields
3315
+ * @param {object} res 3rd parameter to callback
3316
+ * @param {object} fields
3317
3317
  * @param {Query} self
3318
3318
  * @param {Array} [pop] array of paths used in population
3319
3319
  * @param {Function} callback
@@ -3402,26 +3402,26 @@ function prepareDiscriminatorCriteria(query) {
3402
3402
  * @method findOneAndUpdate
3403
3403
  * @memberOf Query
3404
3404
  * @instance
3405
- * @param {Object|Query} [filter]
3406
- * @param {Object} [update]
3407
- * @param {Object} [options]
3408
- * @param {Boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html) rather than just the document
3409
- * @param {Boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3405
+ * @param {object|Query} [filter]
3406
+ * @param {object} [update]
3407
+ * @param {object} [options]
3408
+ * @param {boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/7.0/interfaces/ModifyResult.html) rather than just the document
3409
+ * @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3410
3410
  * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3411
- * @param {Boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
3412
- * @param {Boolean} [options.new=false] By default, `findOneAndUpdate()` returns the document as it was **before** `update` was applied. If you set `new: true`, `findOneAndUpdate()` will instead give you the object after `update` was applied. **Deprecated:** Use `returnDocument: 'after'` instead of `new: true`, or `returnDocument: 'before'` instead of `new: false`.
3413
- * @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and [the Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
3414
- * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
3415
- * @param {Boolean} [options.returnOriginal=null] An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`. **Deprecated:** Use `returnDocument: 'after'` instead of `returnOriginal: false`, or `returnDocument: 'before'` instead of `returnOriginal: true`.
3411
+ * @param {boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
3412
+ * @param {boolean} [options.new=false] By default, `findOneAndUpdate()` returns the document as it was **before** `update` was applied. If you set `new: true`, `findOneAndUpdate()` will instead give you the object after `update` was applied. **Deprecated:** Use `returnDocument: 'after'` instead of `new: true`, or `returnDocument: 'before'` instead of `new: false`.
3413
+ * @param {object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and [the Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
3414
+ * @param {boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
3415
+ * @param {boolean} [options.returnOriginal=null] An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`. **Deprecated:** Use `returnDocument: 'after'` instead of `returnOriginal: false`, or `returnDocument: 'before'` instead of `returnOriginal: true`.
3416
3416
  * @param {'before'|'after'} [options.returnDocument='before'] Has two possible values, `'before'` and `'after'`. By default, it will return the document before the update was applied.
3417
- * @param {Boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
3418
- * @param {Boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
3419
- * @param {Boolean} [options.overwriteImmutable=false] Mongoose removes updated immutable properties from `update` by default (excluding $setOnInsert). Set `overwriteImmutable` to `true` to allow updating immutable properties using other update operators.
3420
- * @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3417
+ * @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
3418
+ * @param {boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
3419
+ * @param {boolean} [options.overwriteImmutable=false] Mongoose removes updated immutable properties from `update` by default (excluding $setOnInsert). Set `overwriteImmutable` to `true` to allow updating immutable properties using other update operators.
3420
+ * @param {boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3421
3421
  * @see Tutorial https://mongoosejs.com/docs/tutorials/findoneandupdate.html
3422
3422
  * @see findAndModify command https://www.mongodb.com/docs/manual/reference/command/findAndModify/
3423
- * @see ModifyResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html
3424
- * @see findOneAndUpdate https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#findOneAndUpdate
3423
+ * @see ModifyResult https://mongodb.github.io/node-mongodb-native/7.0/interfaces/ModifyResult.html
3424
+ * @see findOneAndUpdate https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#findOneAndUpdate
3425
3425
  * @return {Query} this
3426
3426
  * @api public
3427
3427
  */
@@ -3525,11 +3525,14 @@ Query.prototype._findOneAndUpdate = async function _findOneAndUpdate() {
3525
3525
 
3526
3526
  this._update = this._castUpdate(this._update);
3527
3527
 
3528
- const _opts = Object.assign({}, options, {
3529
- setDefaultsOnInsert: this._mongooseOptions.setDefaultsOnInsert
3530
- });
3531
- this._update = setDefaultsOnInsert(this._conditions, this.model.schema,
3532
- this._update, _opts);
3528
+ this._update = setDefaultsOnInsert(
3529
+ this._conditions,
3530
+ this.model.schema,
3531
+ this._update,
3532
+ options,
3533
+ this._mongooseOptions,
3534
+ this
3535
+ );
3533
3536
 
3534
3537
  if (!this._update || utils.hasOwnKeys(this._update) === false) {
3535
3538
  if (options.upsert) {
@@ -3558,7 +3561,7 @@ Query.prototype._findOneAndUpdate = async function _findOneAndUpdate() {
3558
3561
  await this.validate(this._update, options, false);
3559
3562
  }
3560
3563
 
3561
- if (this._update.toBSON) {
3564
+ if (typeof this._update.toBSON === 'function') {
3562
3565
  this._update = this._update.toBSON();
3563
3566
  }
3564
3567
 
@@ -3601,12 +3604,12 @@ Query.prototype._findOneAndUpdate = async function _findOneAndUpdate() {
3601
3604
  *
3602
3605
  * @method findOneAndDelete
3603
3606
  * @memberOf Query
3604
- * @param {Object} [filter]
3605
- * @param {Object} [options]
3606
- * @param {Boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html) rather than just the document
3607
- * @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3607
+ * @param {object} [filter]
3608
+ * @param {object} [options]
3609
+ * @param {boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/7.0/interfaces/ModifyResult.html) rather than just the document
3610
+ * @param {boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3608
3611
  * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3609
- * @param {Boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3612
+ * @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3610
3613
  * @return {Query} this
3611
3614
  * @see findAndModify command https://www.mongodb.com/docs/manual/reference/command/findAndModify/
3612
3615
  * @api public
@@ -3684,7 +3687,7 @@ Query.prototype._findOneAndDelete = async function _findOneAndDelete() {
3684
3687
  *
3685
3688
  * - `sort`: if multiple docs are found by the conditions, sets the sort order to choose which doc to update
3686
3689
  * - `maxTimeMS`: puts a time limit on the query - requires mongodb >= 2.6.0
3687
- * - `includeResultMetadata`: if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html) rather than just the document
3690
+ * - `includeResultMetadata`: if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/7.0/interfaces/ModifyResult.html) rather than just the document
3688
3691
  * - `requireFilter`: bool - if true, throws an error if the filter is empty (`{}`). Defaults to false.
3689
3692
  *
3690
3693
  * #### Example:
@@ -3695,21 +3698,21 @@ Query.prototype._findOneAndDelete = async function _findOneAndDelete() {
3695
3698
  *
3696
3699
  * @method findOneAndReplace
3697
3700
  * @memberOf Query
3698
- * @param {Object} [filter]
3699
- * @param {Object} [replacement]
3700
- * @param {Object} [options]
3701
- * @param {Boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html) rather than just the document
3701
+ * @param {object} [filter]
3702
+ * @param {object} [replacement]
3703
+ * @param {object} [options]
3704
+ * @param {boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/7.0/interfaces/ModifyResult.html) rather than just the document
3702
3705
  * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3703
- * @param {Boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3704
- * @param {Boolean} [options.new=false] By default, `findOneAndUpdate()` returns the document as it was **before** `update` was applied. If you set `new: true`, `findOneAndUpdate()` will instead give you the object after `update` was applied. **Deprecated:** Use `returnDocument: 'after'` instead of `new: true`, or `returnDocument: 'before'` instead of `new: false`.
3705
- * @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and [the Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
3706
+ * @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3707
+ * @param {boolean} [options.new=false] By default, `findOneAndUpdate()` returns the document as it was **before** `update` was applied. If you set `new: true`, `findOneAndUpdate()` will instead give you the object after `update` was applied. **Deprecated:** Use `returnDocument: 'after'` instead of `new: true`, or `returnDocument: 'before'` instead of `new: false`.
3708
+ * @param {object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and [the Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
3706
3709
  * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3707
- * @param {Boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3708
- * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
3709
- * @param {Boolean} [options.returnOriginal=null] An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`. **Deprecated:** Use `returnDocument: 'after'` instead of `returnOriginal: false`, or `returnDocument: 'before'` instead of `returnOriginal: true`.
3710
+ * @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3711
+ * @param {boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
3712
+ * @param {boolean} [options.returnOriginal=null] An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`. **Deprecated:** Use `returnDocument: 'after'` instead of `returnOriginal: false`, or `returnDocument: 'before'` instead of `returnOriginal: true`.
3710
3713
  * @param {'before'|'after'} [options.returnDocument='before'] Has two possible values, `'before'` and `'after'`. By default, it will return the document before the update was applied.
3711
- * @param {Boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
3712
- * @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3714
+ * @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
3715
+ * @param {boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3713
3716
  * @return {Query} this
3714
3717
  * @api public
3715
3718
  */
@@ -3839,10 +3842,10 @@ Query.prototype._findOneAndReplace = async function _findOneAndReplace() {
3839
3842
  * @method findById
3840
3843
  * @memberOf Query
3841
3844
  * @instance
3842
- * @param {Any} id value of `_id` to query by
3843
- * @param {Object} [projection] optional fields to return
3844
- * @param {Object} [options] see [`setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
3845
- * @param {Boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
3845
+ * @param {any} id value of `_id` to query by
3846
+ * @param {object} [projection] optional fields to return
3847
+ * @param {object} [options] see [`setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
3848
+ * @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
3846
3849
  * @return {Query} this
3847
3850
  * @see findOne https://www.mongodb.com/docs/manual/reference/method/db.collection.findOne/
3848
3851
  * @see Query.select https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
@@ -3868,25 +3871,25 @@ Query.prototype.findById = function(id, projection, options) {
3868
3871
  * @method findByIdAndUpdate
3869
3872
  * @memberOf Query
3870
3873
  * @instance
3871
- * @param {Any} id value of `_id` to query by
3872
- * @param {Object} [doc]
3873
- * @param {Object} [options]
3874
- * @param {Boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html) rather than just the document
3875
- * @param {Boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3874
+ * @param {any} id value of `_id` to query by
3875
+ * @param {object} [doc]
3876
+ * @param {object} [options]
3877
+ * @param {boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/7.0/interfaces/ModifyResult.html) rather than just the document
3878
+ * @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3876
3879
  * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3877
- * @param {Boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
3878
- * @param {Boolean} [options.new=false] By default, `findOneAndUpdate()` returns the document as it was **before** `update` was applied. If you set `new: true`, `findOneAndUpdate()` will instead give you the object after `update` was applied. **Deprecated:** Use `returnDocument: 'after'` instead of `new: true`, or `returnDocument: 'before'` instead of `new: false`.
3879
- * @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and [the Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
3880
- * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
3881
- * @param {Boolean} [options.returnOriginal=null] An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`. **Deprecated:** Use `returnDocument: 'after'` instead of `returnOriginal: false`, or `returnDocument: 'before'` instead of `returnOriginal: true`.
3880
+ * @param {boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
3881
+ * @param {boolean} [options.new=false] By default, `findOneAndUpdate()` returns the document as it was **before** `update` was applied. If you set `new: true`, `findOneAndUpdate()` will instead give you the object after `update` was applied. **Deprecated:** Use `returnDocument: 'after'` instead of `new: true`, or `returnDocument: 'before'` instead of `new: false`.
3882
+ * @param {object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and [the Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
3883
+ * @param {boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
3884
+ * @param {boolean} [options.returnOriginal=null] An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`. **Deprecated:** Use `returnDocument: 'after'` instead of `returnOriginal: false`, or `returnDocument: 'before'` instead of `returnOriginal: true`.
3882
3885
  * @param {'before'|'after'} [options.returnDocument='before'] Has two possible values, `'before'` and `'after'`. By default, it will return the document before the update was applied.
3883
- * @param {Boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
3884
- * @param {Boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
3885
- * @param {Boolean} [options.overwriteImmutable=false] Mongoose removes updated immutable properties from `update` by default (excluding $setOnInsert). Set `overwriteImmutable` to `true` to allow updating immutable properties using other update operators.
3886
+ * @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
3887
+ * @param {boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
3888
+ * @param {boolean} [options.overwriteImmutable=false] Mongoose removes updated immutable properties from `update` by default (excluding $setOnInsert). Set `overwriteImmutable` to `true` to allow updating immutable properties using other update operators.
3886
3889
  * @see Tutorial https://mongoosejs.com/docs/tutorials/findoneandupdate.html
3887
3890
  * @see findAndModify command https://www.mongodb.com/docs/manual/reference/command/findAndModify/
3888
- * @see ModifyResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html
3889
- * @see findOneAndUpdate https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#findOneAndUpdate
3891
+ * @see ModifyResult https://mongodb.github.io/node-mongodb-native/7.0/interfaces/ModifyResult.html
3892
+ * @see findOneAndUpdate https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#findOneAndUpdate
3890
3893
  * @return {Query} this
3891
3894
  * @api public
3892
3895
  */
@@ -3907,10 +3910,10 @@ Query.prototype.findByIdAndUpdate = function(id, update, options) {
3907
3910
  * @method findByIdAndDelete
3908
3911
  * @memberOf Query
3909
3912
  * @param {any} id value of `_id` to query by
3910
- * @param {Object} [options]
3911
- * @param {Boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html) rather than just the document
3913
+ * @param {object} [options]
3914
+ * @param {boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/7.0/interfaces/ModifyResult.html) rather than just the document
3912
3915
  * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3913
- * @param {Boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3916
+ * @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3914
3917
  * @return {Query} this
3915
3918
  * @see findAndModify command https://www.mongodb.com/docs/manual/reference/command/findAndModify/
3916
3919
  * @api public
@@ -3954,8 +3957,8 @@ function convertNewToReturnDocument(options) {
3954
3957
  /**
3955
3958
  * Get options from query opts, falling back to the base mongoose object.
3956
3959
  * @param {Query} query
3957
- * @param {Object} option
3958
- * @param {Any} def
3960
+ * @param {object} option
3961
+ * @param {any} def
3959
3962
  * @api private
3960
3963
  */
3961
3964
 
@@ -4038,7 +4041,7 @@ function _completeManyLean(schema, docs, path, opts) {
4038
4041
  * Override mquery.prototype._mergeUpdate to handle mongoose objects in
4039
4042
  * updates.
4040
4043
  *
4041
- * @param {Object} update
4044
+ * @param {object} update
4042
4045
  * @method _mergeUpdate
4043
4046
  * @memberOf Query
4044
4047
  * @instance
@@ -4099,68 +4102,13 @@ function _previewUpdate(update) {
4099
4102
  return preview;
4100
4103
  }
4101
4104
 
4102
- /*!
4103
- * ignore
4104
- */
4105
-
4106
- async function _updateThunk(op) {
4107
- this._applyTranslateAliases();
4108
-
4109
- this._castConditions();
4110
-
4111
- // Check for empty/invalid filter with requireFilter option
4112
- checkRequireFilter(this._conditions, this.options);
4113
-
4114
- _castArrayFilters(this);
4115
-
4116
- if (this.error() != null) {
4117
- throw this.error();
4118
- }
4119
-
4120
- const castedQuery = this._conditions;
4121
- const options = this._optionsForExec(this.model);
4122
-
4123
- this._update = clone(this._update, options);
4124
- const isOverwriting = op === 'replaceOne';
4125
- if (isOverwriting) {
4126
- this._update = new this.model(this._update, null, { skipId: true });
4127
- } else {
4128
- this._update = this._castUpdate(this._update);
4129
-
4130
- if (this._update == null || utils.hasOwnKeys(this._update) === false) {
4131
- return { acknowledged: false };
4132
- }
4133
-
4134
- const _opts = Object.assign({}, options, {
4135
- setDefaultsOnInsert: this._mongooseOptions.setDefaultsOnInsert
4136
- });
4137
- this._update = setDefaultsOnInsert(this._conditions, this.model.schema,
4138
- this._update, _opts);
4139
- }
4140
-
4141
- if (Array.isArray(options.arrayFilters)) {
4142
- options.arrayFilters = removeUnusedArrayFilters(this._update, options.arrayFilters);
4143
- }
4144
-
4145
- const runValidators = _getOption(this, 'runValidators', false);
4146
- if (runValidators) {
4147
- await this.validate(this._update, options, isOverwriting);
4148
- }
4149
-
4150
- if (this._update.toBSON) {
4151
- this._update = this._update.toBSON();
4152
- }
4153
-
4154
- return this.mongooseCollection[op](castedQuery, this._update, options);
4155
- }
4156
-
4157
4105
  /**
4158
4106
  * Mongoose calls this function internally to validate the query if
4159
4107
  * `runValidators` is set
4160
4108
  *
4161
- * @param {Object} castedDoc the update, after casting
4162
- * @param {Object} options the options from `_optionsForExec()`
4163
- * @param {Boolean} isOverwriting
4109
+ * @param {object} castedDoc the update, after casting
4110
+ * @param {object} options the options from `_optionsForExec()`
4111
+ * @param {boolean} isOverwriting
4164
4112
  * @method validate
4165
4113
  * @memberOf Query
4166
4114
  * @instance
@@ -4177,7 +4125,14 @@ Query.prototype.validate = async function validate(castedDoc, options, isOverwri
4177
4125
  if (isOverwriting) {
4178
4126
  await castedDoc.$validate();
4179
4127
  } else {
4180
- await updateValidators(this, this.model.schema, castedDoc, options);
4128
+ const validationErrors = await updateValidators(this, this.model.schema, castedDoc, options);
4129
+ if (validationErrors.length > 0) {
4130
+ const err = new ValidationError(null);
4131
+ for (const validationError of validationErrors) {
4132
+ err.addError(validationError.path, validationError);
4133
+ }
4134
+ throw err;
4135
+ }
4181
4136
  }
4182
4137
 
4183
4138
  await _executePostHooks(this, null, null, 'validate');
@@ -4193,7 +4148,39 @@ Query.prototype.validate = async function validate(castedDoc, options, isOverwri
4193
4148
  * @api private
4194
4149
  */
4195
4150
  Query.prototype._updateMany = async function _updateMany() {
4196
- return _updateThunk.call(this, 'updateMany');
4151
+ this._applyTranslateAliases();
4152
+ this._castConditions();
4153
+ checkRequireFilter(this._conditions, this.options);
4154
+ _castArrayFilters(this);
4155
+ if (this.error() != null) {
4156
+ throw this.error();
4157
+ }
4158
+
4159
+ const options = this._optionsForExec(this.model);
4160
+ this._update = this._castUpdate(this._update);
4161
+ if (this._update == null || utils.hasOwnKeys(this._update) === false) {
4162
+ return { acknowledged: false };
4163
+ }
4164
+ removeUnusedArrayFilters(this._update, options);
4165
+
4166
+ this._update = setDefaultsOnInsert(
4167
+ this._conditions,
4168
+ this.model.schema,
4169
+ this._update,
4170
+ options,
4171
+ this._mongooseOptions,
4172
+ this
4173
+ );
4174
+
4175
+ if (_getOption(this, 'runValidators', false)) {
4176
+ await this.validate(this._update, options, false);
4177
+ }
4178
+
4179
+ if (typeof this._update.toBSON === 'function') {
4180
+ this._update = this._update.toBSON();
4181
+ }
4182
+
4183
+ return this.mongooseCollection.updateMany(this._conditions, this._update, options);
4197
4184
  };
4198
4185
 
4199
4186
  /**
@@ -4206,7 +4193,39 @@ Query.prototype._updateMany = async function _updateMany() {
4206
4193
  * @api private
4207
4194
  */
4208
4195
  Query.prototype._updateOne = async function _updateOne() {
4209
- return _updateThunk.call(this, 'updateOne');
4196
+ this._applyTranslateAliases();
4197
+ this._castConditions();
4198
+ checkRequireFilter(this._conditions, this.options);
4199
+ _castArrayFilters(this);
4200
+ if (this.error() != null) {
4201
+ throw this.error();
4202
+ }
4203
+
4204
+ const options = this._optionsForExec(this.model);
4205
+ this._update = this._castUpdate(this._update);
4206
+ if (this._update == null || utils.hasOwnKeys(this._update) === false) {
4207
+ return { acknowledged: false };
4208
+ }
4209
+ removeUnusedArrayFilters(this._update, options);
4210
+
4211
+ this._update = setDefaultsOnInsert(
4212
+ this._conditions,
4213
+ this.model.schema,
4214
+ this._update,
4215
+ options,
4216
+ this._mongooseOptions,
4217
+ this
4218
+ );
4219
+
4220
+ if (_getOption(this, 'runValidators', false)) {
4221
+ await this.validate(this._update, options, false);
4222
+ }
4223
+
4224
+ if (typeof this._update.toBSON === 'function') {
4225
+ this._update = this._update.toBSON();
4226
+ }
4227
+
4228
+ return this.mongooseCollection.updateOne(this._conditions, this._update, options);
4210
4229
  };
4211
4230
 
4212
4231
  /**
@@ -4219,7 +4238,27 @@ Query.prototype._updateOne = async function _updateOne() {
4219
4238
  * @api private
4220
4239
  */
4221
4240
  Query.prototype._replaceOne = async function _replaceOne() {
4222
- return _updateThunk.call(this, 'replaceOne');
4241
+ this._applyTranslateAliases();
4242
+ this._castConditions();
4243
+ checkRequireFilter(this._conditions, this.options);
4244
+ _castArrayFilters(this);
4245
+ if (this.error() != null) {
4246
+ throw this.error();
4247
+ }
4248
+
4249
+ const options = this._optionsForExec(this.model);
4250
+ this._update = new this.model(this._update, null, { skipId: true });
4251
+ removeUnusedArrayFilters(this._update, options);
4252
+
4253
+ if (_getOption(this, 'runValidators', false)) {
4254
+ await this.validate(this._update, options, true);
4255
+ }
4256
+
4257
+ if (typeof this._update.toBSON === 'function') {
4258
+ this._update = this._update.toBSON();
4259
+ }
4260
+
4261
+ return this.mongooseCollection.replaceOne(this._conditions, this._update, options);
4223
4262
  };
4224
4263
 
4225
4264
  /**
@@ -4243,23 +4282,23 @@ Query.prototype._replaceOne = async function _replaceOne() {
4243
4282
  *
4244
4283
  * - `updateMany()`
4245
4284
  *
4246
- * @param {Object} [filter]
4247
- * @param {Object|Array} [update] the update command. If array, this update will be treated as an update pipeline and not casted.
4248
- * @param {Object} [options]
4249
- * @param {Boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
4250
- * @param {Boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
4251
- * @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
4252
- * @param {Object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](https://mongoosejs.com/docs/guide.html#writeConcern)
4253
- * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Does nothing if schema-level timestamps are not set.
4254
- * @param {Boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
4255
- * @param {Boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
4256
- * @param {Boolean} [options.overwriteImmutable=false] Mongoose removes updated immutable properties from `update` by default (excluding $setOnInsert). Set `overwriteImmutable` to `true` to allow updating immutable properties using other update operators.
4257
- * @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
4285
+ * @param {object} [filter]
4286
+ * @param {object|Array} [update] the update command. If array, this update will be treated as an update pipeline and not casted.
4287
+ * @param {object} [options]
4288
+ * @param {boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
4289
+ * @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
4290
+ * @param {boolean} [options.upsert=false] if true, and no documents found, insert a new document
4291
+ * @param {object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](https://mongoosejs.com/docs/guide.html#writeConcern)
4292
+ * @param {boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Does nothing if schema-level timestamps are not set.
4293
+ * @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
4294
+ * @param {boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
4295
+ * @param {boolean} [options.overwriteImmutable=false] Mongoose removes updated immutable properties from `update` by default (excluding $setOnInsert). Set `overwriteImmutable` to `true` to allow updating immutable properties using other update operators.
4296
+ * @param {boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
4258
4297
  * @return {Query} this
4259
4298
  * @see Model.update https://mongoosejs.com/docs/api/model.html#Model.update()
4260
4299
  * @see Query docs https://mongoosejs.com/docs/queries.html
4261
4300
  * @see update https://www.mongodb.com/docs/manual/reference/method/db.collection.update/
4262
- * @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
4301
+ * @see UpdateResult https://mongodb.github.io/node-mongodb-native/7.0/interfaces/UpdateResult.html
4263
4302
  * @see MongoDB docs https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output
4264
4303
  * @api public
4265
4304
  */
@@ -4318,23 +4357,23 @@ Query.prototype.updateMany = function(conditions, doc, options, callback) {
4318
4357
  *
4319
4358
  * - `updateOne()`
4320
4359
  *
4321
- * @param {Object} [filter]
4322
- * @param {Object|Array} [update] the update command. If array, this update will be treated as an update pipeline and not casted.
4323
- * @param {Object} [options]
4324
- * @param {Boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
4325
- * @param {Boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
4326
- * @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
4327
- * @param {Object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](https://mongoosejs.com/docs/guide.html#writeConcern)
4328
- * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
4329
- * @param {Boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
4330
- * @param {Boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
4331
- * @param {Boolean} [options.overwriteImmutable=false] Mongoose removes updated immutable properties from `update` by default (excluding $setOnInsert). Set `overwriteImmutable` to `true` to allow updating immutable properties using other update operators.
4332
- * @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
4360
+ * @param {object} [filter]
4361
+ * @param {object|Array} [update] the update command. If array, this update will be treated as an update pipeline and not casted.
4362
+ * @param {object} [options]
4363
+ * @param {boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
4364
+ * @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
4365
+ * @param {boolean} [options.upsert=false] if true, and no documents found, insert a new document
4366
+ * @param {object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](https://mongoosejs.com/docs/guide.html#writeConcern)
4367
+ * @param {boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
4368
+ * @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
4369
+ * @param {boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
4370
+ * @param {boolean} [options.overwriteImmutable=false] Mongoose removes updated immutable properties from `update` by default (excluding $setOnInsert). Set `overwriteImmutable` to `true` to allow updating immutable properties using other update operators.
4371
+ * @param {boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
4333
4372
  * @return {Query} this
4334
4373
  * @see Model.update https://mongoosejs.com/docs/api/model.html#Model.update()
4335
4374
  * @see Query docs https://mongoosejs.com/docs/queries.html
4336
4375
  * @see update https://www.mongodb.com/docs/manual/reference/method/db.collection.update/
4337
- * @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
4376
+ * @see UpdateResult https://mongodb.github.io/node-mongodb-native/7.0/interfaces/UpdateResult.html
4338
4377
  * @see MongoDB docs https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output
4339
4378
  * @api public
4340
4379
  */
@@ -4387,21 +4426,21 @@ Query.prototype.updateOne = function(conditions, doc, options, callback) {
4387
4426
  *
4388
4427
  * - `replaceOne()`
4389
4428
  *
4390
- * @param {Object} [filter]
4391
- * @param {Object} [doc] the update command
4392
- * @param {Object} [options]
4393
- * @param {Boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
4394
- * @param {Boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
4395
- * @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
4396
- * @param {Object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](https://mongoosejs.com/docs/guide.html#writeConcern)
4397
- * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Does nothing if schema-level timestamps are not set.
4398
- * @param {Boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
4399
- * @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
4429
+ * @param {object} [filter]
4430
+ * @param {object} [doc] the update command
4431
+ * @param {object} [options]
4432
+ * @param {boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
4433
+ * @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
4434
+ * @param {boolean} [options.upsert=false] if true, and no documents found, insert a new document
4435
+ * @param {object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](https://mongoosejs.com/docs/guide.html#writeConcern)
4436
+ * @param {boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Does nothing if schema-level timestamps are not set.
4437
+ * @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
4438
+ * @param {boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
4400
4439
  * @return {Query} this
4401
4440
  * @see Model.update https://mongoosejs.com/docs/api/model.html#Model.update()
4402
4441
  * @see Query docs https://mongoosejs.com/docs/queries.html
4403
4442
  * @see update https://www.mongodb.com/docs/manual/reference/method/db.collection.update/
4404
- * @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
4443
+ * @see UpdateResult https://mongodb.github.io/node-mongodb-native/7.0/interfaces/UpdateResult.html
4405
4444
  * @see MongoDB docs https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output
4406
4445
  * @api public
4407
4446
  */
@@ -4437,10 +4476,10 @@ Query.prototype.replaceOne = function(conditions, doc, options, callback) {
4437
4476
  /**
4438
4477
  * Internal helper for update, updateMany, updateOne, replaceOne
4439
4478
  * @param {Query} query
4440
- * @param {String} op
4441
- * @param {Object} filter
4479
+ * @param {string} op
4480
+ * @param {object} filter
4442
4481
  * @param {Document} [doc]
4443
- * @param {Object} [options]
4482
+ * @param {object} [options]
4444
4483
  * @param {Function} callback
4445
4484
  * @api private
4446
4485
  */
@@ -4611,8 +4650,8 @@ function _orFailError(err, query) {
4611
4650
 
4612
4651
  /**
4613
4652
  * Wrapper function to call isPathSelectedInclusive on a query.
4614
- * @param {String} path
4615
- * @return {Boolean}
4653
+ * @param {string} path
4654
+ * @return {boolean}
4616
4655
  * @api public
4617
4656
  */
4618
4657
 
@@ -4628,7 +4667,7 @@ Query.prototype.isPathSelectedInclusive = function(path) {
4628
4667
  * const promise = query.exec();
4629
4668
  * const promise = query.exec('update');
4630
4669
  *
4631
- * @param {String|Function} [operation]
4670
+ * @param {string|Function} [operation]
4632
4671
  * @return {Promise}
4633
4672
  * @api public
4634
4673
  */
@@ -4806,7 +4845,7 @@ Query.prototype.finally = function(onFinally) {
4806
4845
  * const q = Model.find();
4807
4846
  * console.log(q); // Prints "Query { find }"
4808
4847
  *
4809
- * @return {String}
4848
+ * @return {string}
4810
4849
  * @api public
4811
4850
  * @method [Symbol.toStringTag]
4812
4851
  * @memberOf Query
@@ -4871,8 +4910,8 @@ Query.prototype.post = function(fn) {
4871
4910
  /**
4872
4911
  * Casts obj for an update command.
4873
4912
  *
4874
- * @param {Object} obj
4875
- * @return {Object} obj after casting its values
4913
+ * @param {object} obj
4914
+ * @return {object} obj after casting its values
4876
4915
  * @method _castUpdate
4877
4916
  * @memberOf Query
4878
4917
  * @instance
@@ -4942,18 +4981,18 @@ Query.prototype._castUpdate = function _castUpdate(obj) {
4942
4981
  * a response for each query has also been returned, the results are passed to
4943
4982
  * the callback.
4944
4983
  *
4945
- * @param {Object|String|String[]} path either the path(s) to populate or an object specifying all parameters
4946
- * @param {Object|String} [select] Field selection for the population query
4984
+ * @param {object|string|Array<string>} path either the path(s) to populate or an object specifying all parameters
4985
+ * @param {object|string} [select] Field selection for the population query
4947
4986
  * @param {Model} [model] The model you wish to use for population. If not specified, populate will look up the model by the name in the Schema's `ref` field.
4948
- * @param {Object} [match] Conditions for the population query
4949
- * @param {Object} [options] Options for the population query (sort, etc)
4950
- * @param {String} [options.path=null] The path to populate.
4987
+ * @param {object} [match] Conditions for the population query
4988
+ * @param {object} [options] Options for the population query (sort, etc)
4989
+ * @param {string} [options.path=null] The path to populate.
4951
4990
  * @param {boolean} [options.retainNullValues=false] by default, Mongoose removes null and undefined values from populated arrays. Use this option to make `populate()` retain `null` and `undefined` array entries.
4952
4991
  * @param {boolean} [options.getters=false] if true, Mongoose will call any getters defined on the `localField`. By default, Mongoose gets the raw value of `localField`. For example, you would need to set this option to `true` if you wanted to [add a `lowercase` getter to your `localField`](https://mongoosejs.com/docs/schematypes.html#schematype-options).
4953
4992
  * @param {boolean} [options.clone=false] When you do `BlogPost.find().populate('author')`, blog posts with the same author will share 1 copy of an `author` doc. Enable this option to make Mongoose clone populated docs before assigning them.
4954
- * @param {Object|Function} [options.match=null] Add an additional filter to the populate query. Can be a filter object containing [MongoDB query syntax](https://www.mongodb.com/docs/manual/tutorial/query-documents/), or a function that returns a filter object.
4993
+ * @param {object|Function} [options.match=null] Add an additional filter to the populate query. Can be a filter object containing [MongoDB query syntax](https://www.mongodb.com/docs/manual/tutorial/query-documents/), or a function that returns a filter object.
4955
4994
  * @param {Function} [options.transform=null] Function that Mongoose will call on every populated document that allows you to transform the populated document.
4956
- * @param {Object} [options.options=null] Additional options like `limit` and `lean`.
4995
+ * @param {object} [options.options=null] Additional options like `limit` and `lean`.
4957
4996
  * @see population https://mongoosejs.com/docs/populate.html
4958
4997
  * @see Query#select https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
4959
4998
  * @see Model.populate https://mongoosejs.com/docs/api/model.html#Model.populate()
@@ -5057,8 +5096,8 @@ function _getPopulatedPaths(list, arr, prefix) {
5057
5096
  * If `obj` is present, it is cast instead of this query.
5058
5097
  *
5059
5098
  * @param {Model} [model] the model to cast to. If not set, defaults to `this.model`
5060
- * @param {Object} [obj]
5061
- * @return {Object}
5099
+ * @param {object} [obj]
5100
+ * @return {object}
5062
5101
  * @api public
5063
5102
  */
5064
5103
 
@@ -5100,7 +5139,7 @@ Query.prototype.cast = function(model, obj) {
5100
5139
  *
5101
5140
  * query.select({ ids: { $elemMatch: { $in: [hexString] }})
5102
5141
  *
5103
- * @param {Object} fields
5142
+ * @param {object} fields
5104
5143
  * @see https://github.com/Automattic/mongoose/issues/1091
5105
5144
  * @see https://www.mongodb.com/docs/manual/reference/projection/elemMatch/
5106
5145
  * @api private
@@ -5187,7 +5226,7 @@ Query.prototype._applyPaths = function applyPaths() {
5187
5226
  };
5188
5227
 
5189
5228
  /**
5190
- * Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html).
5229
+ * Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/7.0/classes/FindCursor.html).
5191
5230
  * A QueryCursor exposes a Streams3 interface, as well as a `.next()` function.
5192
5231
  *
5193
5232
  * The `.cursor()` function triggers pre find hooks, but **not** post find hooks.
@@ -5221,7 +5260,7 @@ Query.prototype._applyPaths = function applyPaths() {
5221
5260
  * - `transform`: optional function which accepts a mongoose document. The return value of the function will be emitted on `data` and returned by `.next()`.
5222
5261
  *
5223
5262
  * @return {QueryCursor}
5224
- * @param {Object} [options]
5263
+ * @param {object} [options]
5225
5264
  * @see QueryCursor https://mongoosejs.com/docs/api/querycursor.html
5226
5265
  * @api public
5227
5266
  */
@@ -5258,10 +5297,10 @@ Query.prototype.cursor = function cursor(opts) {
5258
5297
  *
5259
5298
  * Cannot be used with `distinct()`
5260
5299
  *
5261
- * @param {Boolean} bool defaults to true
5262
- * @param {Object} [opts] options to set
5263
- * @param {Boolean} [opts.awaitData] false by default. Set to true to keep the cursor open even if there's no data.
5264
- * @param {Number} [opts.maxAwaitTimeMS] the maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. Requires `tailable` and `awaitData` to be true
5300
+ * @param {boolean} bool defaults to true
5301
+ * @param {object} [opts] options to set
5302
+ * @param {boolean} [opts.awaitData] false by default. Set to true to keep the cursor open even if there's no data.
5303
+ * @param {number} [opts.maxAwaitTimeMS] the maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. Requires `tailable` and `awaitData` to be true
5265
5304
  * @see tailable https://www.mongodb.com/docs/manual/tutorial/create-tailable-cursor/
5266
5305
  * @api public
5267
5306
  */
@@ -5320,7 +5359,7 @@ Query.prototype.tailable = function(val, opts) {
5320
5359
  * @method intersects
5321
5360
  * @memberOf Query
5322
5361
  * @instance
5323
- * @param {Object} [arg]
5362
+ * @param {object} [arg]
5324
5363
  * @return {Query} this
5325
5364
  * @see $geometry https://www.mongodb.com/docs/manual/reference/operator/geometry/
5326
5365
  * @see geoIntersects https://www.mongodb.com/docs/manual/reference/operator/geoIntersects/
@@ -5359,7 +5398,7 @@ Query.prototype.tailable = function(val, opts) {
5359
5398
  * @method geometry
5360
5399
  * @memberOf Query
5361
5400
  * @instance
5362
- * @param {Object} object Must contain a `type` property which is a String and a `coordinates` property which is an Array. See the examples.
5401
+ * @param {object} object Must contain a `type` property which is a String and a `coordinates` property which is an Array. See the examples.
5363
5402
  * @return {Query} this
5364
5403
  * @see $geometry https://www.mongodb.com/docs/manual/reference/operator/geometry/
5365
5404
  * @see Geospatial Support Enhancements https://www.mongodb.com/docs/manual/release-notes/2.4/#geospatial-support-enhancements
@@ -5382,8 +5421,8 @@ Query.prototype.tailable = function(val, opts) {
5382
5421
  * @method near
5383
5422
  * @memberOf Query
5384
5423
  * @instance
5385
- * @param {String} [path]
5386
- * @param {Object} val
5424
+ * @param {string} [path]
5425
+ * @param {object} val
5387
5426
  * @return {Query} this
5388
5427
  * @see $near https://www.mongodb.com/docs/manual/reference/operator/near/
5389
5428
  * @see $nearSphere https://www.mongodb.com/docs/manual/reference/operator/nearSphere/
@@ -5518,8 +5557,8 @@ Query.prototype[Symbol.asyncIterator] = function queryAsyncIterator() {
5518
5557
  * @method polygon
5519
5558
  * @memberOf Query
5520
5559
  * @instance
5521
- * @param {String|Array} [path]
5522
- * @param {...Array|Object} [coordinatePairs]
5560
+ * @param {string|Array} [path]
5561
+ * @param {...Array|object} [coordinatePairs]
5523
5562
  * @return {Query} this
5524
5563
  * @see $polygon https://www.mongodb.com/docs/manual/reference/operator/polygon/
5525
5564
  * @see MongoDB Geospatial Indexing https://www.mongodb.com/docs/manual/core/geospatial-indexes/
@@ -5543,8 +5582,8 @@ Query.prototype[Symbol.asyncIterator] = function queryAsyncIterator() {
5543
5582
  * @see $box https://www.mongodb.com/docs/manual/reference/operator/box/
5544
5583
  * @see within() Query#within https://mongoosejs.com/docs/api/query.html#Query.prototype.within()
5545
5584
  * @see MongoDB Geospatial Indexing https://www.mongodb.com/docs/manual/core/geospatial-indexes/
5546
- * @param {Object|Array<Number>} val1 Lower Left Coordinates OR a object of lower-left(ll) and upper-right(ur) Coordinates
5547
- * @param {Array<Number>} [val2] Upper Right Coordinates
5585
+ * @param {object|Array<number>} val1 Lower Left Coordinates OR a object of lower-left(ll) and upper-right(ur) Coordinates
5586
+ * @param {Array<number>} [val2] Upper Right Coordinates
5548
5587
  * @return {Query} this
5549
5588
  * @api public
5550
5589
  */
@@ -5587,8 +5626,8 @@ Query.prototype.box = function(ll, ur) {
5587
5626
  * @method circle
5588
5627
  * @memberOf Query
5589
5628
  * @instance
5590
- * @param {String} [path]
5591
- * @param {Object} area
5629
+ * @param {string} [path]
5630
+ * @param {object} area
5592
5631
  * @return {Query} this
5593
5632
  * @see $center https://www.mongodb.com/docs/manual/reference/operator/center/
5594
5633
  * @see $centerSphere https://www.mongodb.com/docs/manual/reference/operator/centerSphere/
@@ -5622,8 +5661,8 @@ Query.prototype.center = Query.base.circle;
5622
5661
  * query.where('loc').within().centerSphere(area);
5623
5662
  *
5624
5663
  * @deprecated
5625
- * @param {String} [path]
5626
- * @param {Object} val
5664
+ * @param {string} [path]
5665
+ * @param {object} val
5627
5666
  * @return {Query} this
5628
5667
  * @see MongoDB Geospatial Indexing https://www.mongodb.com/docs/manual/core/geospatial-indexes/
5629
5668
  * @see $centerSphere https://www.mongodb.com/docs/manual/reference/operator/centerSphere/
@@ -5648,7 +5687,7 @@ Query.prototype.centerSphere = function() {
5648
5687
  * @method selected
5649
5688
  * @memberOf Query
5650
5689
  * @instance
5651
- * @return {Boolean}
5690
+ * @return {boolean}
5652
5691
  * @api public
5653
5692
  */
5654
5693
 
@@ -5662,7 +5701,7 @@ Query.prototype.centerSphere = function() {
5662
5701
  * @method selectedInclusively
5663
5702
  * @memberOf Query
5664
5703
  * @instance
5665
- * @return {Boolean}
5704
+ * @return {boolean}
5666
5705
  * @api public
5667
5706
  */
5668
5707
 
@@ -5681,7 +5720,7 @@ Query.prototype.selectedInclusively = function selectedInclusively() {
5681
5720
  * @method selectedExclusively
5682
5721
  * @memberOf Query
5683
5722
  * @instance
5684
- * @return {Boolean}
5723
+ * @return {boolean}
5685
5724
  * @api public
5686
5725
  */
5687
5726