mongoose 6.5.2 → 6.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/.mocharc.yml +2 -0
  2. package/dist/browser.umd.js +1148 -68091
  3. package/lib/aggregate.js +7 -7
  4. package/lib/browserDocument.js +1 -1
  5. package/lib/cast/boolean.js +1 -1
  6. package/lib/cast/number.js +1 -1
  7. package/lib/cast/string.js +1 -1
  8. package/lib/cast.js +3 -0
  9. package/lib/connection.js +19 -11
  10. package/lib/cursor/AggregationCursor.js +16 -5
  11. package/lib/cursor/QueryCursor.js +16 -5
  12. package/lib/document.js +31 -18
  13. package/lib/drivers/browser/objectid.js +2 -1
  14. package/lib/drivers/node-mongodb-native/ReadPreference.js +1 -1
  15. package/lib/drivers/node-mongodb-native/collection.js +6 -2
  16. package/lib/error/browserMissingSchema.js +1 -1
  17. package/lib/error/cast.js +2 -1
  18. package/lib/error/divergentArray.js +2 -1
  19. package/lib/error/missingSchema.js +2 -1
  20. package/lib/error/notFound.js +2 -1
  21. package/lib/error/overwriteModel.js +2 -1
  22. package/lib/error/strictPopulate.js +29 -0
  23. package/lib/error/validation.js +9 -7
  24. package/lib/error/validator.js +8 -4
  25. package/lib/helpers/clone.js +1 -1
  26. package/lib/helpers/discriminator/getConstructor.js +2 -1
  27. package/lib/helpers/discriminator/getDiscriminatorByValue.js +7 -6
  28. package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +7 -6
  29. package/lib/helpers/document/compile.js +14 -2
  30. package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +5 -1
  31. package/lib/helpers/get.js +2 -1
  32. package/lib/helpers/getConstructorName.js +2 -1
  33. package/lib/helpers/indexes/isIndexEqual.js +6 -6
  34. package/lib/helpers/isBsonType.js +2 -1
  35. package/lib/helpers/isMongooseObject.js +2 -2
  36. package/lib/helpers/isObject.js +1 -1
  37. package/lib/helpers/isSimpleValidator.js +1 -1
  38. package/lib/helpers/model/applyHooks.js +11 -0
  39. package/lib/helpers/model/applyMethods.js +11 -1
  40. package/lib/helpers/model/applyStatics.js +2 -1
  41. package/lib/helpers/model/castBulkWrite.js +7 -2
  42. package/lib/helpers/model/discriminator.js +3 -1
  43. package/lib/helpers/path/flattenObjectWithDottedPaths.js +3 -2
  44. package/lib/helpers/pluralize.js +1 -1
  45. package/lib/helpers/populate/assignRawDocsToIdStructure.js +5 -3
  46. package/lib/helpers/populate/assignVals.js +14 -3
  47. package/lib/helpers/populate/createPopulateQueryFilter.js +8 -2
  48. package/lib/helpers/populate/getModelsMapForPopulate.js +5 -4
  49. package/lib/helpers/populate/getSchemaTypes.js +3 -1
  50. package/lib/helpers/populate/markArraySubdocsPopulated.js +5 -1
  51. package/lib/helpers/projection/hasIncludedChildren.js +4 -1
  52. package/lib/helpers/projection/isPathExcluded.js +3 -2
  53. package/lib/helpers/projection/isSubpath.js +2 -1
  54. package/lib/helpers/query/applyQueryMiddleware.js +3 -2
  55. package/lib/helpers/query/castUpdate.js +14 -8
  56. package/lib/helpers/query/completeMany.js +3 -2
  57. package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +7 -1
  58. package/lib/helpers/query/wrapThunk.js +3 -1
  59. package/lib/helpers/schema/getIndexes.js +7 -2
  60. package/lib/helpers/schema/getPath.js +4 -3
  61. package/lib/helpers/schema/idGetter.js +2 -1
  62. package/lib/helpers/setDefaultsOnInsert.js +15 -0
  63. package/lib/index.js +20 -12
  64. package/lib/model.js +219 -145
  65. package/lib/query.js +160 -65
  66. package/lib/queryhelpers.js +4 -4
  67. package/lib/schema/SubdocumentPath.js +1 -1
  68. package/lib/schema/array.js +2 -2
  69. package/lib/schema/date.js +2 -1
  70. package/lib/schema/documentarray.js +4 -3
  71. package/lib/schema/operators/helpers.js +2 -2
  72. package/lib/schema/operators/text.js +1 -1
  73. package/lib/schema/string.js +1 -1
  74. package/lib/schema.js +14 -5
  75. package/lib/schematype.js +17 -4
  76. package/lib/statemachine.js +13 -12
  77. package/lib/types/ArraySubdocument.js +13 -3
  78. package/lib/types/DocumentArray/methods/index.js +9 -5
  79. package/lib/types/array/methods/index.js +5 -4
  80. package/lib/types/map.js +3 -1
  81. package/lib/types/objectid.js +2 -2
  82. package/lib/types/subdocument.js +30 -8
  83. package/lib/utils.js +58 -31
  84. package/package.json +11 -11
  85. package/scripts/create-tarball.js +7 -0
  86. package/types/aggregate.d.ts +3 -3
  87. package/types/connection.d.ts +4 -4
  88. package/types/cursor.d.ts +1 -1
  89. package/types/document.d.ts +2 -2
  90. package/types/index.d.ts +13 -27
  91. package/types/indexes.d.ts +2 -2
  92. package/types/middlewares.d.ts +1 -1
  93. package/types/models.d.ts +14 -11
  94. package/types/pipelinestage.d.ts +1 -1
  95. package/types/query.d.ts +33 -16
package/lib/utils.js CHANGED
@@ -30,7 +30,7 @@ exports.isMongooseDocumentArray = isMongooseDocumentArray.isMongooseDocumentArra
30
30
  exports.registerMongooseArray = isMongooseArray.registerMongooseArray;
31
31
  exports.registerMongooseDocumentArray = isMongooseDocumentArray.registerMongooseDocumentArray;
32
32
 
33
- /*!
33
+ /**
34
34
  * Produces a collection name from model `name`. By default, just returns
35
35
  * the model name
36
36
  *
@@ -53,7 +53,7 @@ exports.toCollectionName = function(name, pluralize) {
53
53
  return name;
54
54
  };
55
55
 
56
- /*!
56
+ /**
57
57
  * Determines if `a` and `b` are deep equal.
58
58
  *
59
59
  * Modified from node/lib/assert.js
@@ -174,8 +174,9 @@ exports.deepEqual = function deepEqual(a, b) {
174
174
  return true;
175
175
  };
176
176
 
177
- /*!
177
+ /**
178
178
  * Get the last element of an array
179
+ * @param {Array} arr
179
180
  */
180
181
 
181
182
  exports.last = function(arr) {
@@ -225,11 +226,11 @@ exports.omit = function omit(obj, keys) {
225
226
  };
226
227
 
227
228
 
228
- /*!
229
+ /**
229
230
  * Shallow copies defaults into options.
230
231
  *
231
232
  * @param {Object} defaults
232
- * @param {Object} options
233
+ * @param {Object} [options]
233
234
  * @return {Object} the merged object
234
235
  * @api private
235
236
  */
@@ -251,11 +252,13 @@ exports.options = function(defaults, options) {
251
252
  return options;
252
253
  };
253
254
 
254
- /*!
255
+ /**
255
256
  * Merges `from` into `to` without overwriting existing properties.
256
257
  *
257
258
  * @param {Object} to
258
259
  * @param {Object} from
260
+ * @param {Object} [options]
261
+ * @param {String} [path]
259
262
  * @api private
260
263
  */
261
264
 
@@ -318,7 +321,7 @@ exports.merge = function merge(to, from, options, path) {
318
321
  }
319
322
  };
320
323
 
321
- /*!
324
+ /**
322
325
  * Applies toObject recursively.
323
326
  *
324
327
  * @param {Document|Array|Object} obj
@@ -370,7 +373,7 @@ exports.toObject = function toObject(obj) {
370
373
 
371
374
  exports.isObject = isObject;
372
375
 
373
- /*!
376
+ /**
374
377
  * Determines if `arg` is a plain old JavaScript object (POJO). Specifically,
375
378
  * `arg` must be an object but not an instance of any special class, like String,
376
379
  * ObjectId, etc.
@@ -393,9 +396,10 @@ exports.isPOJO = function isPOJO(arg) {
393
396
  return !proto || proto.constructor.name === 'Object';
394
397
  };
395
398
 
396
- /*!
399
+ /**
397
400
  * Determines if `arg` is an object that isn't an instance of a built-in value
398
401
  * class, like Array, Buffer, ObjectId, etc.
402
+ * @param {Any} val
399
403
  */
400
404
 
401
405
  exports.isNonBuiltinObject = function isNonBuiltinObject(val) {
@@ -405,9 +409,10 @@ exports.isNonBuiltinObject = function isNonBuiltinObject(val) {
405
409
  val != null;
406
410
  };
407
411
 
408
- /*!
412
+ /**
409
413
  * Determines if `obj` is a built-in object like an array, date, boolean,
410
414
  * etc.
415
+ * @param {Any} arg
411
416
  */
412
417
 
413
418
  exports.isNativeObject = function(arg) {
@@ -418,8 +423,9 @@ exports.isNativeObject = function(arg) {
418
423
  arg instanceof String;
419
424
  };
420
425
 
421
- /*!
426
+ /**
422
427
  * Determines if `val` is an object that has no own keys
428
+ * @param {Any} val
423
429
  */
424
430
 
425
431
  exports.isEmptyObject = function(val) {
@@ -428,9 +434,11 @@ exports.isEmptyObject = function(val) {
428
434
  Object.keys(val).length === 0;
429
435
  };
430
436
 
431
- /*!
437
+ /**
432
438
  * Search if `obj` or any POJOs nested underneath `obj` has a property named
433
439
  * `key`
440
+ * @param {Object} obj
441
+ * @param {String} key
434
442
  */
435
443
 
436
444
  exports.hasKey = function hasKey(obj, key) {
@@ -446,7 +454,7 @@ exports.hasKey = function hasKey(obj, key) {
446
454
  return false;
447
455
  };
448
456
 
449
- /*!
457
+ /**
450
458
  * process.nextTick helper.
451
459
  *
452
460
  * Wraps `callback` in a try/catch + nextTick.
@@ -474,9 +482,10 @@ exports.tick = function tick(callback) {
474
482
  };
475
483
  };
476
484
 
477
- /*!
485
+ /**
478
486
  * Returns true if `v` is an object that can be serialized as a primitive in
479
487
  * MongoDB
488
+ * @param {Any} v
480
489
  */
481
490
 
482
491
  exports.isMongooseType = function(v) {
@@ -485,7 +494,7 @@ exports.isMongooseType = function(v) {
485
494
 
486
495
  exports.isMongooseObject = isMongooseObject;
487
496
 
488
- /*!
497
+ /**
489
498
  * Converts `expires` options of index objects to `expiresAfterSeconds` options for MongoDB.
490
499
  *
491
500
  * @param {Object} object
@@ -506,8 +515,16 @@ exports.expires = function expires(object) {
506
515
  delete object.expires;
507
516
  };
508
517
 
509
- /*!
518
+ /**
510
519
  * populate helper
520
+ * @param {String} path
521
+ * @param {String} select
522
+ * @param {Model} model
523
+ * @param {Object} match
524
+ * @param {Object} options
525
+ * @param {Any} subPopulate
526
+ * @param {Boolean} justOne
527
+ * @param {Boolean} count
511
528
  */
512
529
 
513
530
  exports.populate = function populate(path, select, model, match, options, subPopulate, justOne, count) {
@@ -613,35 +630,38 @@ function _populateObj(obj) {
613
630
  return ret;
614
631
  }
615
632
 
616
- /*!
633
+ /**
617
634
  * Return the value of `obj` at the given `path`.
618
635
  *
619
636
  * @param {String} path
620
637
  * @param {Object} obj
638
+ * @param {Any} map
621
639
  */
622
640
 
623
641
  exports.getValue = function(path, obj, map) {
624
642
  return mpath.get(path, obj, '_doc', map);
625
643
  };
626
644
 
627
- /*!
645
+ /**
628
646
  * Sets the value of `obj` at the given `path`.
629
647
  *
630
648
  * @param {String} path
631
649
  * @param {Anything} val
632
650
  * @param {Object} obj
651
+ * @param {Any} map
652
+ * @param {Any} _copying
633
653
  */
634
654
 
635
655
  exports.setValue = function(path, val, obj, map, _copying) {
636
656
  mpath.set(path, val, obj, '_doc', map, _copying);
637
657
  };
638
658
 
639
- /*!
659
+ /**
640
660
  * Returns an array of values from object `o`.
641
661
  *
642
662
  * @param {Object} o
643
663
  * @return {Array}
644
- * @private
664
+ * @api private
645
665
  */
646
666
 
647
667
  exports.object = {};
@@ -657,27 +677,29 @@ exports.object.vals = function vals(o) {
657
677
  return ret;
658
678
  };
659
679
 
660
- /*!
680
+ /**
661
681
  * @see exports.options
662
682
  */
663
683
 
664
684
  exports.object.shallowCopy = exports.options;
665
685
 
666
- /*!
686
+ const hop = Object.prototype.hasOwnProperty;
687
+
688
+ /**
667
689
  * Safer helper for hasOwnProperty checks
668
690
  *
669
691
  * @param {Object} obj
670
692
  * @param {String} prop
671
693
  */
672
694
 
673
- const hop = Object.prototype.hasOwnProperty;
674
695
  exports.object.hasOwnProperty = function(obj, prop) {
675
696
  return hop.call(obj, prop);
676
697
  };
677
698
 
678
- /*!
699
+ /**
679
700
  * Determine if `val` is null or undefined
680
701
  *
702
+ * @param {Any} val
681
703
  * @return {Boolean}
682
704
  */
683
705
 
@@ -691,15 +713,16 @@ exports.isNullOrUndefined = function(val) {
691
713
 
692
714
  exports.array = {};
693
715
 
694
- /*!
716
+ /**
695
717
  * Flattens an array.
696
718
  *
697
719
  * [ 1, [ 2, 3, [4] ]] -> [1,2,3,4]
698
720
  *
699
721
  * @param {Array} arr
700
722
  * @param {Function} [filter] If passed, will be invoked with each item in the array. If `filter` returns a falsy value, the item will not be included in the results.
723
+ * @param {Array} ret
701
724
  * @return {Array}
702
- * @private
725
+ * @api private
703
726
  */
704
727
 
705
728
  exports.array.flatten = function flatten(arr, filter, ret) {
@@ -770,7 +793,7 @@ exports.isArrayIndex = function(val) {
770
793
  return false;
771
794
  };
772
795
 
773
- /*!
796
+ /**
774
797
  * Removes duplicate values from an array
775
798
  *
776
799
  * [1, 2, 3, 3, 5] => [1, 2, 3, 5]
@@ -779,7 +802,7 @@ exports.isArrayIndex = function(val) {
779
802
  *
780
803
  * @param {Array} arr
781
804
  * @return {Array}
782
- * @private
805
+ * @api private
783
806
  */
784
807
 
785
808
  exports.array.unique = function(arr) {
@@ -808,14 +831,15 @@ exports.array.unique = function(arr) {
808
831
  return ret;
809
832
  };
810
833
 
811
- /*!
834
+ exports.buffer = {};
835
+
836
+ /**
812
837
  * Determines if two buffers are equal.
813
838
  *
814
839
  * @param {Buffer} a
815
840
  * @param {Object} b
816
841
  */
817
842
 
818
- exports.buffer = {};
819
843
  exports.buffer.areEqual = function(a, b) {
820
844
  if (!Buffer.isBuffer(a)) {
821
845
  return false;
@@ -835,8 +859,11 @@ exports.buffer.areEqual = function(a, b) {
835
859
  };
836
860
 
837
861
  exports.getFunctionName = getFunctionName;
838
- /*!
862
+
863
+ /**
839
864
  * Decorate buffers
865
+ * @param {Object} destination
866
+ * @param {Object} source
840
867
  */
841
868
 
842
869
  exports.decorate = function(destination, source) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "6.5.2",
4
+ "version": "6.5.5",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -28,9 +28,9 @@
28
28
  "sift": "16.0.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@babel/core": "7.18.10",
32
- "@typescript-eslint/eslint-plugin": "5.32.0",
33
- "@typescript-eslint/parser": "5.32.0",
31
+ "@babel/core": "7.18.13",
32
+ "@typescript-eslint/eslint-plugin": "5.36.1",
33
+ "@typescript-eslint/parser": "5.36.1",
34
34
  "acquit": "1.2.1",
35
35
  "acquit-ignore": "0.2.0",
36
36
  "acquit-require": "0.1.1",
@@ -42,27 +42,27 @@
42
42
  "buffer": "^5.6.0",
43
43
  "cheerio": "1.0.0-rc.12",
44
44
  "crypto-browserify": "3.12.0",
45
- "dox": "0.9.1",
46
- "eslint": "8.21.0",
45
+ "dox": "1.0.0",
46
+ "eslint": "8.23.0",
47
47
  "eslint-plugin-mocha-no-only": "1.1.1",
48
+ "express": "^4.18.1",
48
49
  "highlight.js": "11.6.0",
49
50
  "lodash.isequal": "4.5.0",
50
51
  "lodash.isequalwith": "4.4.0",
51
- "marked": "4.0.18",
52
+ "marked": "4.1.0",
52
53
  "mkdirp": "^1.0.4",
53
54
  "mocha": "10.0.0",
54
55
  "moment": "2.x",
55
- "mongodb-memory-server": "8.8.0",
56
+ "mongodb-memory-server": "8.9.1",
56
57
  "ncp": "^2.0.0",
57
58
  "nyc": "15.1.0",
58
59
  "pug": "3.0.2",
59
60
  "q": "1.5.1",
60
- "serve-handler": "6.1.3",
61
61
  "sinon": "14.0.0",
62
62
  "stream-browserify": "3.0.0",
63
63
  "ts-benchmark": "^1.1.10",
64
- "tsd": "0.20.0",
65
- "typescript": "4.7.4",
64
+ "tsd": "0.23.0",
65
+ "typescript": "4.8.2",
66
66
  "uuid": "8.3.2",
67
67
  "webpack": "5.74.0"
68
68
  },
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const { execSync } = require('child_process');
4
+ const { name, version } = require('../package.json');
5
+
6
+ execSync('npm pack');
7
+ execSync(`mv ${name}-${version}.tgz ${name}.tgz`);
@@ -91,7 +91,7 @@ declare module 'mongoose' {
91
91
  */
92
92
  addFields(arg: PipelineStage.AddFields['$addFields']): this;
93
93
 
94
- /** Sets the allowDiskUse option for the aggregation query (ignored for < 2.6.0) */
94
+ /** Sets the allowDiskUse option for the aggregation query */
95
95
  allowDiskUse(value: boolean): this;
96
96
 
97
97
  /** Appends new operators to this aggregate pipeline */
@@ -111,7 +111,7 @@ declare module 'mongoose' {
111
111
  count(fieldName: PipelineStage.Count['$count']): this;
112
112
 
113
113
  /**
114
- * Sets the cursor option for the aggregation query (ignored for < 2.6.0).
114
+ * Sets the cursor option for the aggregation query
115
115
  */
116
116
  cursor<DocType = any>(options?: Record<string, unknown>): Cursor<DocType>;
117
117
 
@@ -134,7 +134,7 @@ declare module 'mongoose' {
134
134
  /** Appends new custom $group operator to this aggregate pipeline. */
135
135
  group(arg: PipelineStage.Group['$group']): this;
136
136
 
137
- /** Sets the hint option for the aggregation query (ignored for < 3.6.0) */
137
+ /** Sets the hint option for the aggregation query */
138
138
  hint(value: Record<string, unknown> | string): this;
139
139
 
140
140
  /**
@@ -117,7 +117,7 @@ declare module 'mongoose' {
117
117
  get(key: string): any;
118
118
 
119
119
  /**
120
- * Returns the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
120
+ * Returns the [MongoDB driver `MongoClient`](https://mongodb.github.io/node-mongodb-native/4.9/classes/MongoClient.html) instance
121
121
  * that this connection uses to talk to MongoDB.
122
122
  */
123
123
  getClient(): mongodb.MongoClient;
@@ -150,11 +150,11 @@ declare module 'mongoose' {
150
150
  ): Model<InferSchemaType<TSchema>, ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>, ObtainSchemaGeneric<TSchema, 'TInstanceMethods'>, {}, TSchema> & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
151
151
  model<T, U, TQueryHelpers = {}>(
152
152
  name: string,
153
- schema?: Schema<T, U, any, TQueryHelpers, any, any>,
153
+ schema?: Schema<T, any, any, TQueryHelpers, any, any>,
154
154
  collection?: string,
155
155
  options?: CompileModelOptions
156
156
  ): U;
157
- model<T>(name: string, schema?: Schema<T>, collection?: string, options?: CompileModelOptions): Model<T>;
157
+ model<T>(name: string, schema?: Schema<T, any, any> | Schema<T & Document, any, any>, collection?: string, options?: CompileModelOptions): Model<T>;
158
158
 
159
159
  /** Returns an array of model names created on this connection. */
160
160
  modelNames(): Array<string>;
@@ -197,7 +197,7 @@ declare module 'mongoose' {
197
197
  set(key: string, value: any): any;
198
198
 
199
199
  /**
200
- * Set the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
200
+ * Set the [MongoDB driver `MongoClient`](https://mongodb.github.io/node-mongodb-native/4.9/classes/MongoClient.html) instance
201
201
  * that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to
202
202
  * reuse it.
203
203
  */
package/types/cursor.d.ts CHANGED
@@ -14,7 +14,7 @@ declare module 'mongoose' {
14
14
  [Symbol.asyncIterator](): AsyncIterableIterator<DocType>;
15
15
 
16
16
  /**
17
- * Adds a [cursor flag](http://mongodb.github.io/node-mongodb-native/2.2/api/Cursor.html#addCursorFlag).
17
+ * Adds a [cursor flag](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html#addCursorFlag).
18
18
  * Useful for setting the `noCursorTimeout` and `tailable` flags.
19
19
  */
20
20
  addCursorFlag(flag: CursorFlag, value: boolean): this;
@@ -26,7 +26,7 @@ declare module 'mongoose' {
26
26
  __v?: any;
27
27
 
28
28
  /** Assert that a given path or paths is populated. Throws an error if not populated. */
29
- $assertPopulated<Paths = {}>(paths: string | string[]): Omit<DocType, keyof Paths> & Paths;
29
+ $assertPopulated<Paths = {}>(path: string | string[], values?: Partial<Paths>): Omit<this, keyof Paths> & Paths;
30
30
 
31
31
  /* Get all subdocs (by bfs) */
32
32
  $getAllSubdocs(): Document[];
@@ -164,7 +164,7 @@ declare module 'mongoose' {
164
164
  invalidate(path: string, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null;
165
165
 
166
166
  /** Returns true if `path` was directly set and modified, else false. */
167
- isDirectModified(path: string): boolean;
167
+ isDirectModified(path: string | Array<string>): boolean;
168
168
 
169
169
  /** Checks if `path` was explicitly selected. If no projection, always returns true. */
170
170
  isDirectSelected(path: string): boolean;
package/types/index.d.ts CHANGED
@@ -62,7 +62,10 @@ declare module 'mongoose' {
62
62
  export function get<K extends keyof MongooseOptions>(key: K): MongooseOptions[K];
63
63
 
64
64
  /* ! ignore */
65
- export type CompileModelOptions = { overwriteModels?: boolean, connection?: Connection };
65
+ export type CompileModelOptions = {
66
+ overwriteModels?: boolean,
67
+ connection?: Connection
68
+ };
66
69
 
67
70
  export function model<TSchema extends Schema = any>(
68
71
  name: string,
@@ -113,10 +116,6 @@ declare module 'mongoose' {
113
116
  ? IfAny<U, T & { _id: Types.ObjectId }, T & Required<{ _id: U }>>
114
117
  : T & { _id: Types.ObjectId };
115
118
 
116
- export type RequireOnlyTypedId<T> = T extends { _id?: infer U; }
117
- ? Required<{ _id: U }>
118
- : { _id: Types.ObjectId };
119
-
120
119
  export type HydratedDocument<DocType, TMethodsAndOverrides = {}, TVirtuals = {}> = DocType extends Document ? Require_id<DocType> : (Document<unknown, any, DocType> & Require_id<DocType> & TVirtuals & TMethodsAndOverrides);
121
120
 
122
121
  export interface TagSet {
@@ -196,7 +195,7 @@ declare module 'mongoose' {
196
195
  /** Returns a copy of this schema */
197
196
  clone<T = this>(): T;
198
197
 
199
- discriminator<T extends Schema = Schema>(name: string, schema: T): DiscriminatorSchema<DocType, M, TInstanceMethods, TQueryHelpers, TVirtuals, T>;
198
+ discriminator<T = Schema>(name: string, schema: T): DiscriminatorSchema<DocType, M, TInstanceMethods, TQueryHelpers, TVirtuals, T>;
200
199
 
201
200
  /** Returns a new schema that has the picked `paths` from this schema. */
202
201
  pick<T = this>(paths: string[], options?: SchemaOptions): T;
@@ -257,8 +256,8 @@ declare module 'mongoose' {
257
256
  /** Defines a post hook for the model. */
258
257
  post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PostMiddlewareFunction<T, T>): this;
259
258
  post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
260
- post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
261
- post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
259
+ post<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
260
+ post<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
262
261
  post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PostMiddlewareFunction<T, Array<AggregateExtract<T>>>): this;
263
262
  post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, Array<AggregateExtract<T>>>): this;
264
263
  post<T = M>(method: 'insertMany' | RegExp, fn: PostMiddlewareFunction<T, T>): this;
@@ -266,8 +265,8 @@ declare module 'mongoose' {
266
265
 
267
266
  post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
268
267
  post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
269
- post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
270
- post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
268
+ post<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
269
+ post<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
271
270
  post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: ErrorHandlingMiddlewareFunction<T, Array<any>>): this;
272
271
  post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T, Array<any>>): this;
273
272
  post<T = M>(method: 'insertMany' | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
@@ -278,9 +277,8 @@ declare module 'mongoose' {
278
277
  pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', options: SchemaPreOptions, fn: PreSaveMiddlewareFunction<T>): this;
279
278
  pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PreMiddlewareFunction<T>): this;
280
279
  pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
281
- pre<T extends Query<any, any>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
282
- pre<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PreMiddlewareFunction<T>): this;
283
- pre<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
280
+ pre<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, fn: PreMiddlewareFunction<T>): this;
281
+ pre<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
284
282
  pre<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PreMiddlewareFunction<T>): this;
285
283
  pre<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
286
284
  pre<T = M>(method: 'insertMany' | RegExp, fn: (this: T, next: (err?: CallbackError) => void, docs: any | Array<any>) => void | Promise<void>): this;
@@ -452,10 +450,6 @@ declare module 'mongoose' {
452
450
 
453
451
  export type SortOrder = -1 | 1 | 'asc' | 'ascending' | 'desc' | 'descending';
454
452
 
455
- type Mutable<T> = {
456
- -readonly [K in keyof T]: T[K];
457
- };
458
-
459
453
  type _UpdateQuery<TSchema> = {
460
454
  /** @see https://docs.mongodb.com/manual/reference/operator/update-field/ */
461
455
  $currentDate?: AnyKeys<TSchema> & AnyObject;
@@ -469,7 +463,7 @@ declare module 'mongoose' {
469
463
  $unset?: AnyKeys<TSchema> & AnyObject;
470
464
 
471
465
  /** @see https://docs.mongodb.com/manual/reference/operator/update-array/ */
472
- $addToSet?: Mutable<mongodb.SetFields<TSchema>>;
466
+ $addToSet?: AnyKeys<TSchema> & AnyObject;
473
467
  $pop?: AnyKeys<TSchema> & AnyObject;
474
468
  $pull?: AnyKeys<TSchema> & AnyObject;
475
469
  $push?: AnyKeys<TSchema> & AnyObject;
@@ -487,13 +481,6 @@ declare module 'mongoose' {
487
481
  { $replaceRoot: any } |
488
482
  { $replaceWith: any };
489
483
 
490
- export type __UpdateDefProperty<T> =
491
- [Extract<T, mongodb.ObjectId>] extends [never] ? T :
492
- T | string;
493
- export type _UpdateQueryDef<T> = {
494
- [K in keyof T]?: __UpdateDefProperty<T[K]>;
495
- };
496
-
497
484
  /**
498
485
  * Update query command to perform on the document
499
486
  * @example
@@ -501,7 +488,7 @@ declare module 'mongoose' {
501
488
  * { age: 30 }
502
489
  * ```
503
490
  */
504
- export type UpdateQuery<T> = _UpdateQuery<_UpdateQueryDef<T>> & AnyObject;
491
+ export type UpdateQuery<T> = _UpdateQuery<T> & AnyObject;
505
492
 
506
493
  export type DocumentDefinition<T> = {
507
494
  [K in keyof Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>>]:
@@ -527,7 +514,6 @@ declare module 'mongoose' {
527
514
  T extends Types.Subdocument ? Omit<LeanDocument<T>, '$isSingleNested' | 'ownerDocument' | 'parent'> :
528
515
  LeanDocument<T>; // Documents and everything else
529
516
 
530
-
531
517
  export type LeanArray<T extends unknown[]> = T extends unknown[][] ? LeanArray<T[number]>[] : LeanType<T[number]>[];
532
518
 
533
519
  export type _LeanDocument<T> = {
@@ -12,7 +12,7 @@ declare module 'mongoose' {
12
12
 
13
13
  interface IndexManager {
14
14
  /**
15
- * Similar to `ensureIndexes()`, except for it uses the [`createIndex`](http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#createIndex)
15
+ * Similar to `ensureIndexes()`, except for it uses the [`createIndex`](https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#createIndex)
16
16
  * function.
17
17
  */
18
18
  createIndexes(options: mongodb.CreateIndexesOptions, callback: CallbackWithoutResult): void;
@@ -62,7 +62,7 @@ declare module 'mongoose' {
62
62
  toDrop: Array<any>
63
63
  }
64
64
 
65
- type IndexDirection = 1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text';
65
+ type IndexDirection = 1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text' | 'ascending' | 'asc' | 'descending' | 'desc';
66
66
  type IndexDefinition = Record<string, IndexDirection>;
67
67
 
68
68
  interface SyncIndexesOptions extends mongodb.CreateIndexesOptions {
@@ -1,7 +1,7 @@
1
1
  declare module 'mongoose' {
2
2
 
3
3
  type MongooseDocumentMiddleware = 'validate' | 'save' | 'remove' | 'updateOne' | 'deleteOne' | 'init';
4
- type MongooseQueryMiddleware = 'count' | 'deleteMany' | 'deleteOne' | 'distinct' | 'find' | 'findOne' | 'findOneAndDelete' | 'findOneAndRemove' | 'findOneAndUpdate' | 'remove' | 'update' | 'updateOne' | 'updateMany';
4
+ type MongooseQueryMiddleware = 'count' | 'deleteMany' | 'deleteOne' | 'distinct' | 'find' | 'findOne' | 'findOneAndDelete' | 'findOneAndRemove' | 'findOneAndReplace' | 'findOneAndUpdate' | 'remove' | 'replaceOne' | 'update' | 'updateOne' | 'updateMany';
5
5
 
6
6
  type MiddlewareOptions = { document?: boolean, query?: boolean };
7
7
  type SchemaPreOptions = MiddlewareOptions;