mongoose 6.3.9 → 6.4.2

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 (129) hide show
  1. package/.eslintrc.json +65 -36
  2. package/dist/browser.umd.js +68579 -2
  3. package/lib/cast/date.js +1 -1
  4. package/lib/cast/decimal128.js +1 -1
  5. package/lib/cast/objectid.js +1 -1
  6. package/lib/cast.js +1 -1
  7. package/lib/connection.js +47 -5
  8. package/lib/document.js +48 -8
  9. package/lib/drivers/node-mongodb-native/index.js +1 -1
  10. package/lib/error/parallelValidate.js +1 -1
  11. package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +1 -1
  12. package/lib/helpers/aggregate/stringifyFunctionOperators.js +1 -1
  13. package/lib/helpers/arrayDepth.js +1 -1
  14. package/lib/helpers/cursor/eachAsync.js +1 -1
  15. package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
  16. package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +1 -1
  17. package/lib/helpers/discriminator/getConstructor.js +1 -1
  18. package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
  19. package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
  20. package/lib/helpers/document/handleSpreadDoc.js +1 -1
  21. package/lib/helpers/each.js +1 -1
  22. package/lib/helpers/get.js +1 -1
  23. package/lib/helpers/getConstructorName.js +1 -1
  24. package/lib/helpers/getDefaultBulkwriteResult.js +1 -1
  25. package/lib/helpers/indexes/applySchemaCollation.js +1 -1
  26. package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
  27. package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
  28. package/lib/helpers/indexes/isTextIndex.js +1 -1
  29. package/lib/helpers/isMongooseObject.js +1 -1
  30. package/lib/helpers/isObject.js +1 -1
  31. package/lib/helpers/isPromise.js +1 -1
  32. package/lib/helpers/model/applyHooks.js +1 -1
  33. package/lib/helpers/model/applyStaticHooks.js +1 -1
  34. package/lib/helpers/once.js +1 -1
  35. package/lib/helpers/path/flattenObjectWithDottedPaths.js +1 -1
  36. package/lib/helpers/path/parentPaths.js +1 -1
  37. package/lib/helpers/path/setDottedPath.js +1 -1
  38. package/lib/helpers/pluralize.js +1 -1
  39. package/lib/helpers/populate/SkipPopulateValue.js +1 -1
  40. package/lib/helpers/populate/assignRawDocsToIdStructure.js +1 -1
  41. package/lib/helpers/populate/assignVals.js +1 -1
  42. package/lib/helpers/populate/createPopulateQueryFilter.js +1 -1
  43. package/lib/helpers/populate/getModelsMapForPopulate.js +1 -1
  44. package/lib/helpers/populate/leanPopulateMap.js +1 -1
  45. package/lib/helpers/populate/lookupLocalFields.js +1 -1
  46. package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
  47. package/lib/helpers/populate/modelNamesFromRefPath.js +1 -1
  48. package/lib/helpers/populate/removeDeselectedForeignField.js +1 -1
  49. package/lib/helpers/populate/validateRef.js +1 -1
  50. package/lib/helpers/printJestWarning.js +1 -1
  51. package/lib/helpers/processConnectionOptions.js +1 -1
  52. package/lib/helpers/projection/applyProjection.js +1 -1
  53. package/lib/helpers/projection/hasIncludedChildren.js +1 -1
  54. package/lib/helpers/projection/parseProjection.js +1 -1
  55. package/lib/helpers/query/applyGlobalOption.js +1 -1
  56. package/lib/helpers/query/applyQueryMiddleware.js +1 -1
  57. package/lib/helpers/query/cast$expr.js +1 -1
  58. package/lib/helpers/query/castFilterPath.js +1 -1
  59. package/lib/helpers/query/sanitizeFilter.js +1 -1
  60. package/lib/helpers/query/sanitizeProjection.js +1 -1
  61. package/lib/helpers/query/trusted.js +1 -1
  62. package/lib/helpers/query/validOps.js +1 -1
  63. package/lib/helpers/query/wrapThunk.js +1 -1
  64. package/lib/helpers/schema/addAutoId.js +1 -1
  65. package/lib/helpers/schema/applyPlugins.js +1 -1
  66. package/lib/helpers/schema/cleanPositionalOperators.js +1 -1
  67. package/lib/helpers/schema/getKeysInSchemaOrder.js +1 -1
  68. package/lib/helpers/schema/getPath.js +1 -1
  69. package/lib/helpers/schema/handleIdOption.js +1 -1
  70. package/lib/helpers/schema/handleTimestampOption.js +1 -1
  71. package/lib/helpers/specialProperties.js +1 -1
  72. package/lib/helpers/symbols.js +1 -1
  73. package/lib/helpers/timers.js +1 -1
  74. package/lib/helpers/timestamps/setupTimestamps.js +5 -2
  75. package/lib/helpers/topology/allServersUnknown.js +1 -1
  76. package/lib/helpers/topology/isAtlas.js +1 -1
  77. package/lib/helpers/topology/isSSLError.js +1 -1
  78. package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
  79. package/lib/helpers/update/castArrayFilters.js +1 -1
  80. package/lib/helpers/update/moveImmutableProperties.js +1 -1
  81. package/lib/helpers/update/removeUnusedArrayFilters.js +1 -1
  82. package/lib/helpers/update/updatedPathsByArrayFilter.js +1 -1
  83. package/lib/helpers/updateValidators.js +11 -18
  84. package/lib/index.js +108 -29
  85. package/lib/model.js +1 -1
  86. package/lib/options/PopulateOptions.js +1 -1
  87. package/lib/options/SchemaArrayOptions.js +1 -1
  88. package/lib/options/SchemaBufferOptions.js +1 -1
  89. package/lib/options/SchemaDocumentArrayOptions.js +1 -1
  90. package/lib/options/SchemaMapOptions.js +1 -1
  91. package/lib/options/SchemaNumberOptions.js +1 -1
  92. package/lib/options/SchemaObjectIdOptions.js +1 -1
  93. package/lib/options/SchemaSubdocumentOptions.js +1 -1
  94. package/lib/options/SchemaTypeOptions.js +1 -1
  95. package/lib/options/VirtualOptions.js +1 -1
  96. package/lib/options/propertyOptions.js +1 -1
  97. package/lib/options/removeOptions.js +1 -1
  98. package/lib/options/saveOptions.js +1 -1
  99. package/lib/plugins/trackTransaction.js +1 -1
  100. package/lib/query.js +61 -6
  101. package/lib/queryhelpers.js +5 -0
  102. package/lib/schema/array.js +1 -1
  103. package/lib/schema/date.js +2 -2
  104. package/lib/schema/documentarray.js +10 -0
  105. package/lib/schema/number.js +2 -2
  106. package/lib/schema/string.js +2 -2
  107. package/lib/schema/symbols.js +1 -1
  108. package/lib/schema.js +6 -7
  109. package/lib/statemachine.js +13 -0
  110. package/lib/types/DocumentArray/methods/index.js +1 -1
  111. package/lib/utils.js +3 -0
  112. package/lib/validoptions.js +1 -0
  113. package/package.json +3 -3
  114. package/tsconfig.json +1 -0
  115. package/types/collection.d.ts +1 -1
  116. package/types/connection.d.ts +5 -0
  117. package/types/document.d.ts +15 -6
  118. package/types/expressions.d.ts +2882 -0
  119. package/types/index.d.ts +46 -17
  120. package/types/{indizes.d.ts → indexes.d.ts} +2 -2
  121. package/types/inferschematype.d.ts +173 -0
  122. package/types/middlewares.d.ts +1 -1
  123. package/types/models.d.ts +86 -71
  124. package/types/mongooseoptions.d.ts +9 -1
  125. package/types/pipelinestage.d.ts +76 -80
  126. package/types/query.d.ts +1 -1
  127. package/types/schemaoptions.d.ts +22 -4
  128. package/types/types.d.ts +3 -1
  129. package/types/utility.d.ts +9 -0
package/lib/query.js CHANGED
@@ -27,6 +27,7 @@ const immediate = require('./helpers/immediate');
27
27
  const isExclusive = require('./helpers/projection/isExclusive');
28
28
  const isInclusive = require('./helpers/projection/isInclusive');
29
29
  const isSubpath = require('./helpers/projection/isSubpath');
30
+ const mpath = require('mpath');
30
31
  const mquery = require('mquery');
31
32
  const parseProjection = require('./helpers/projection/parseProjection');
32
33
  const removeUnusedArrayFilters = require('./helpers/update/removeUnusedArrayFilters');
@@ -2196,7 +2197,6 @@ function _castArrayFilters(query) {
2196
2197
  * @api private
2197
2198
  */
2198
2199
  Query.prototype._find = wrapThunk(function(callback) {
2199
-
2200
2200
  this._castConditions();
2201
2201
 
2202
2202
  if (this.error() != null) {
@@ -2220,7 +2220,8 @@ Query.prototype._find = wrapThunk(function(callback) {
2220
2220
  // Separate options to pass down to `completeMany()` in case we need to
2221
2221
  // set a session on the document
2222
2222
  const completeManyOptions = Object.assign({}, {
2223
- session: this && this.options && this.options.session || null
2223
+ session: this && this.options && this.options.session || null,
2224
+ lean: mongooseOptions.lean || null
2224
2225
  });
2225
2226
 
2226
2227
  const cb = (err, docs) => {
@@ -2244,7 +2245,9 @@ Query.prototype._find = wrapThunk(function(callback) {
2244
2245
  });
2245
2246
  }
2246
2247
  return mongooseOptions.lean ?
2247
- callback(null, docs) :
2248
+ // call _completeManyLean here?
2249
+ _completeManyLean(_this.model.schema, docs, null, completeManyOptions, callback) :
2250
+ // callback(null, docs) :
2248
2251
  completeMany(_this.model, docs, fields, userProvidedFields, completeManyOptions, callback);
2249
2252
  }
2250
2253
 
@@ -2418,6 +2421,9 @@ Query.prototype._completeOne = function(doc, res, callback) {
2418
2421
  const mongooseOptions = this._mongooseOptions;
2419
2422
  // `rawResult`
2420
2423
  const options = this.options;
2424
+ if (!options.lean && mongooseOptions.lean) {
2425
+ options.lean = mongooseOptions.lean;
2426
+ }
2421
2427
 
2422
2428
  if (options.explain) {
2423
2429
  return callback(null, doc);
@@ -2431,7 +2437,7 @@ Query.prototype._completeOne = function(doc, res, callback) {
2431
2437
  }
2432
2438
  }
2433
2439
  return mongooseOptions.lean ?
2434
- _completeOneLean(doc, res, options, callback) :
2440
+ _completeOneLean(model.schema, doc, null, res, options, callback) :
2435
2441
  completeOne(model, doc, res, options, projection, userProvidedFields,
2436
2442
  null, callback);
2437
2443
  }
@@ -2442,7 +2448,7 @@ Query.prototype._completeOne = function(doc, res, callback) {
2442
2448
  if (err != null) {
2443
2449
  return callback(err);
2444
2450
  }
2445
- _completeOneLean(doc, res, options, callback);
2451
+ _completeOneLean(model.schema, doc, null, res, options, callback);
2446
2452
  });
2447
2453
  }
2448
2454
 
@@ -4009,13 +4015,62 @@ Query.prototype._findAndModify = function(type, callback) {
4009
4015
  * ignore
4010
4016
  */
4011
4017
 
4012
- function _completeOneLean(doc, res, opts, callback) {
4018
+ function _completeOneLean(schema, doc, path, res, opts, callback) {
4019
+ if (opts.lean && opts.lean.transform) {
4020
+ for (let i = 0; i < schema.childSchemas.length; i++) {
4021
+ const childPath = path ? path + '.' + schema.childSchemas[i].model.path : schema.childSchemas[i].model.path;
4022
+ const _schema = schema.childSchemas[i].schema;
4023
+ const obj = mpath.get(childPath, doc);
4024
+ if (obj == null) {
4025
+ continue;
4026
+ }
4027
+ if (Array.isArray(obj)) {
4028
+ for (let i = 0; i < obj.length; i++) {
4029
+ opts.lean.transform(obj[i]);
4030
+ }
4031
+ } else {
4032
+ opts.lean.transform(obj);
4033
+ }
4034
+ _completeOneLean(_schema, obj, childPath, res, opts);
4035
+ }
4036
+ if (callback) {
4037
+ return callback(null, doc);
4038
+ } else {
4039
+ return;
4040
+ }
4041
+ }
4013
4042
  if (opts.rawResult) {
4014
4043
  return callback(null, res);
4015
4044
  }
4016
4045
  return callback(null, doc);
4017
4046
  }
4018
4047
 
4048
+ /*!
4049
+ * ignore
4050
+ */
4051
+
4052
+ function _completeManyLean(schema, docs, path, opts, callback) {
4053
+ if (opts.lean && opts.lean.transform) {
4054
+ for (let i = 0; i < schema.childSchemas.length; i++) {
4055
+ const childPath = path ? path + '.' + schema.childSchemas[i].model.path : schema.childSchemas[i].model.path;
4056
+ const _schema = schema.childSchemas[i].schema;
4057
+ let doc = mpath.get(childPath, docs);
4058
+ if (doc == null) {
4059
+ continue;
4060
+ }
4061
+ doc = doc.flat();
4062
+ for (let i = 0; i < doc.length; i++) {
4063
+ opts.lean.transform(doc[i]);
4064
+ }
4065
+ _completeManyLean(_schema, doc, childPath, opts);
4066
+ }
4067
+ }
4068
+
4069
+ if (!callback) {
4070
+ return;
4071
+ }
4072
+ return callback(null, docs);
4073
+ }
4019
4074
  /*!
4020
4075
  * Override mquery.prototype._mergeUpdate to handle mongoose objects in
4021
4076
  * updates.
@@ -209,6 +209,11 @@ exports.applyPaths = function applyPaths(fields, schema) {
209
209
  // user didn't specify fields, implies returning all fields.
210
210
  // only need to apply excluded fields and delete any plus paths
211
211
  for (const fieldName of excluded) {
212
+ if (fields[fieldName] != null) {
213
+ // Skip applying default projections to fields with non-defining
214
+ // projections, like `$slice`
215
+ continue;
216
+ }
212
217
  fields[fieldName] = 0;
213
218
  }
214
219
  break;
@@ -212,7 +212,7 @@ SchemaArray.checkRequired = SchemaType.checkRequired;
212
212
  */
213
213
 
214
214
  SchemaArray.prototype.checkRequired = function checkRequired(value, doc) {
215
- if (SchemaType._isRef(this, value, doc, true)) {
215
+ if (typeof value === 'object' && SchemaType._isRef(this, value, doc, true)) {
216
216
  return !!value;
217
217
  }
218
218
 
@@ -195,8 +195,8 @@ SchemaDate.checkRequired = SchemaType.checkRequired;
195
195
  */
196
196
 
197
197
  SchemaDate.prototype.checkRequired = function(value, doc) {
198
- if (SchemaType._isRef(this, value, doc, true)) {
199
- return !!value;
198
+ if (typeof value === 'object' && SchemaType._isRef(this, value, doc, true)) {
199
+ return value != null;
200
200
  }
201
201
 
202
202
  // `require('util').inherits()` does **not** copy static properties, and
@@ -10,6 +10,7 @@ const EventEmitter = require('events').EventEmitter;
10
10
  const SchemaDocumentArrayOptions =
11
11
  require('../options/SchemaDocumentArrayOptions');
12
12
  const SchemaType = require('../schematype');
13
+ const SubdocumentPath = require('./SubdocumentPath');
13
14
  const discriminator = require('../helpers/model/discriminator');
14
15
  const handleIdOption = require('../helpers/schema/handleIdOption');
15
16
  const handleSpreadDoc = require('../helpers/document/handleSpreadDoc');
@@ -75,6 +76,15 @@ function DocumentArrayPath(key, schema, options, schemaOptions) {
75
76
  this.$embeddedSchemaType.cast = function(value, doc, init) {
76
77
  return parentSchemaType.cast(value, doc, init)[0];
77
78
  };
79
+ this.$embeddedSchemaType.doValidate = function(value, fn, scope, options) {
80
+ const Constructor = getConstructor(this.caster, value);
81
+
82
+ if (value && !(value instanceof Constructor)) {
83
+ value = new Constructor(value, scope, null, null, options && options.index != null ? options.index : null);
84
+ }
85
+
86
+ return SubdocumentPath.prototype.doValidate.call(this, value, fn, scope, options);
87
+ };
78
88
  this.$embeddedSchemaType.$isMongooseDocumentArrayElement = true;
79
89
  this.$embeddedSchemaType.caster = this.Constructor;
80
90
  this.$embeddedSchemaType.schema = this.schema;
@@ -164,8 +164,8 @@ SchemaNumber.checkRequired = SchemaType.checkRequired;
164
164
  */
165
165
 
166
166
  SchemaNumber.prototype.checkRequired = function checkRequired(value, doc) {
167
- if (SchemaType._isRef(this, value, doc, true)) {
168
- return !!value;
167
+ if (typeof value === 'object' && SchemaType._isRef(this, value, doc, true)) {
168
+ return value != null;
169
169
  }
170
170
 
171
171
  // `require('util').inherits()` does **not** copy static properties, and
@@ -561,8 +561,8 @@ SchemaString.prototype.match = function match(regExp, message) {
561
561
  */
562
562
 
563
563
  SchemaString.prototype.checkRequired = function checkRequired(value, doc) {
564
- if (SchemaType._isRef(this, value, doc, true)) {
565
- return !!value;
564
+ if (typeof value === 'object' && SchemaType._isRef(this, value, doc, true)) {
565
+ return value != null;
566
566
  }
567
567
 
568
568
  // `require('util').inherits()` does **not** copy static properties, and
@@ -2,4 +2,4 @@
2
2
 
3
3
  exports.schemaMixedSymbol = Symbol.for('mongoose:schema_mixed');
4
4
 
5
- exports.builtInMiddleware = Symbol.for('mongoose:built-in-middleware');
5
+ exports.builtInMiddleware = Symbol.for('mongoose:built-in-middleware');
package/lib/schema.js CHANGED
@@ -107,11 +107,11 @@ function Schema(obj, options) {
107
107
  this.inherits = {};
108
108
  this.callQueue = [];
109
109
  this._indexes = [];
110
- this.methods = {};
110
+ this.methods = (options && options.methods) || {};
111
111
  this.methodOptions = {};
112
- this.statics = {};
112
+ this.statics = (options && options.statics) || {};
113
113
  this.tree = {};
114
- this.query = {};
114
+ this.query = (options && options.query) || {};
115
115
  this.childSchemas = [];
116
116
  this.plugins = [];
117
117
  // For internal debugging. Do not use this to try to save a schema in MDB.
@@ -477,7 +477,7 @@ Schema.prototype.defaultOptions = function(options) {
477
477
  * Inherit a Schema by applying a discriminator on an existing Schema.
478
478
  *
479
479
  *
480
- * ####Example:
480
+ * #### Example:
481
481
  *
482
482
  * const options = { discriminatorKey: 'kind' };
483
483
  *
@@ -648,7 +648,7 @@ Schema.prototype.add = function add(obj, prefix) {
648
648
  * removeIndex only removes indexes from your schema object. Does **not** affect the indexes
649
649
  * in MongoDB.
650
650
  *
651
- * ####Example:
651
+ * #### Example:
652
652
  *
653
653
  * const ToySchema = new Schema({ name: String, color: String, price: Number });
654
654
  *
@@ -701,7 +701,7 @@ Schema.prototype.removeIndex = function removeIndex(index) {
701
701
  * clearIndexes only removes indexes from your schema object. Does **not** affect the indexes
702
702
  * in MongoDB.
703
703
  *
704
- * ####Example:
704
+ * #### Example:
705
705
  *
706
706
  * const ToySchema = new Schema({ name: String, color: String, price: Number });
707
707
  * ToySchema.index({ name: 1 });
@@ -766,7 +766,6 @@ reserved['prototype'] =
766
766
  // EventEmitter
767
767
  reserved.emit =
768
768
  reserved.listeners =
769
- reserved.on =
770
769
  reserved.removeListener =
771
770
 
772
771
  // document properties and functions
@@ -95,6 +95,19 @@ StateMachine.prototype.clear = function clear(state) {
95
95
  }
96
96
  };
97
97
 
98
+ /*!
99
+ * ignore
100
+ */
101
+
102
+ StateMachine.prototype.clearPath = function clearPath(path) {
103
+ const state = this.paths[path];
104
+ if (!state) {
105
+ return;
106
+ }
107
+ delete this.paths[path];
108
+ delete this.states[state][path];
109
+ };
110
+
98
111
  /*!
99
112
  * Checks to see if at least one path is in the states passed in via `arguments`
100
113
  * e.g., this.some('required', 'inited')
@@ -376,4 +376,4 @@ function _updateParentPopulated(arr) {
376
376
 
377
377
  parent.$__.populated[path].value = arr.map(val => val.$populated(remnant));
378
378
  }
379
- }
379
+ }
package/lib/utils.js CHANGED
@@ -935,6 +935,9 @@ exports.getOption = function(name) {
935
935
  const sources = Array.prototype.slice.call(arguments, 1);
936
936
 
937
937
  for (const source of sources) {
938
+ if (source == null) {
939
+ continue;
940
+ }
938
941
  if (source[name] != null) {
939
942
  return source[name];
940
943
  }
@@ -15,6 +15,7 @@ const VALID_OPTIONS = Object.freeze([
15
15
  'bufferTimeoutMS',
16
16
  'cloneSchemas',
17
17
  'debug',
18
+ 'timestamps.createdAt.immutable',
18
19
  'maxTimeMS',
19
20
  'objectIdGetter',
20
21
  'overwriteModels',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "6.3.9",
4
+ "version": "6.4.2",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -20,8 +20,8 @@
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
22
  "bson": "^4.6.2",
23
- "kareem": "2.3.5",
24
- "mongodb": "4.5.0",
23
+ "kareem": "2.4.1",
24
+ "mongodb": "4.7.0",
25
25
  "mpath": "0.9.0",
26
26
  "mquery": "4.0.3",
27
27
  "ms": "2.1.3",
package/tsconfig.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "strict": true,
3
4
  "strictNullChecks": true,
4
5
  "paths": {
5
6
  "mongoose" : ["./types/index.d.ts"]
@@ -43,4 +43,4 @@ declare module 'mongoose' {
43
43
  getIndexes(): ReturnType<mongodb.Collection<T>['indexInformation']>;
44
44
  }
45
45
  let Collection: Collection;
46
- }
46
+ }
@@ -66,6 +66,11 @@ declare module 'mongoose' {
66
66
  close(callback: CallbackWithoutResult): void;
67
67
  close(force?: boolean): Promise<void>;
68
68
 
69
+ /** Closes and destroys the connection. Connection once destroyed cannot be reopened */
70
+ destroy(force: boolean, callback: CallbackWithoutResult): void;
71
+ destroy(callback: CallbackWithoutResult): void;
72
+ destroy(force?: boolean): Promise<void>;
73
+
69
74
  /** Retrieves a collection, creating it if not cached. */
70
75
  collection<T extends AnyObject = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Collection<T>;
71
76
 
@@ -4,6 +4,12 @@ declare module 'mongoose' {
4
4
  /** A list of paths to skip. If set, Mongoose will validate every modified path that is not in this list. */
5
5
  type pathsToSkip = string[] | string;
6
6
 
7
+ interface DocumentSetOptions {
8
+ merge?: boolean;
9
+
10
+ [key: string]: any;
11
+ }
12
+
7
13
  /**
8
14
  * Generic types for Document:
9
15
  * * T - the type of _id
@@ -19,6 +25,9 @@ declare module 'mongoose' {
19
25
  /** This documents __v. */
20
26
  __v?: any;
21
27
 
28
+ /** Assert that a given path or paths is populated. Throws an error if not populated. */
29
+ $assertPopulated<Paths = {}>(paths: string | string[]): Omit<this, keyof Paths> & Paths;
30
+
22
31
  /* Get all subdocs (by bfs) */
23
32
  $getAllSubdocs(): Document[];
24
33
 
@@ -71,8 +80,8 @@ declare module 'mongoose' {
71
80
  $session(session?: ClientSession | null): ClientSession | null;
72
81
 
73
82
  /** Alias for `set()`, used internally to avoid conflicts */
74
- $set(path: string, val: any, type: any, options?: any): this;
75
- $set(path: string, val: any, options?: any): this;
83
+ $set(path: string, val: any, type: any, options?: DocumentSetOptions): this;
84
+ $set(path: string, val: any, options?: DocumentSetOptions): this;
76
85
  $set(value: any): this;
77
86
 
78
87
  /** Set this property to add additional query filters when Mongoose saves this document and `isNew` is false. */
@@ -191,10 +200,10 @@ declare module 'mongoose' {
191
200
  $parent(): Document | undefined;
192
201
 
193
202
  /** Populates document references. */
194
- populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<this & Paths>;
195
- populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<this & Paths>): void;
196
- populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<unknown>, match?: AnyObject, options?: PopulateOptions): Promise<this & Paths>;
197
- populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<unknown>, match?: AnyObject, options?: PopulateOptions, callback?: Callback<this & Paths>): void;
203
+ populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<MergeType<this, Paths>>;
204
+ populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<MergeType<this, Paths>>): void;
205
+ populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions): Promise<MergeType<this, Paths>>;
206
+ populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions, callback?: Callback<MergeType<this, Paths>>): void;
198
207
 
199
208
  /** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */
200
209
  populated(path: string): any;