mongoose 8.17.0 → 8.17.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.
package/lib/document.js CHANGED
@@ -4070,15 +4070,17 @@ Document.prototype.$__toObjectShallow = function $__toObjectShallow(schemaFields
4070
4070
  *
4071
4071
  * If you want to skip transformations, use `transform: false`:
4072
4072
  *
4073
- * schema.options.toObject.hide = '_id';
4074
- * schema.options.toObject.transform = function (doc, ret, options) {
4075
- * if (options.hide) {
4076
- * options.hide.split(' ').forEach(function (prop) {
4077
- * delete ret[prop];
4078
- * });
4073
+ * schema.options.toObject = {
4074
+ * hide: '_id',
4075
+ * transform: function(doc, ret, options) {
4076
+ * if (options.hide) {
4077
+ * options.hide.split(' ').forEach(function(prop) {
4078
+ * delete ret[prop];
4079
+ * });
4080
+ * }
4081
+ * return ret;
4079
4082
  * }
4080
- * return ret;
4081
- * }
4083
+ * };
4082
4084
  *
4083
4085
  * const doc = new Doc({ _id: 'anId', secret: 47, name: 'Wreck-it Ralph' });
4084
4086
  * doc.toObject(); // { secret: 47, name: 'Wreck-it Ralph' }
@@ -14,7 +14,8 @@ const CUSTOMIZABLE_DISCRIMINATOR_OPTIONS = {
14
14
  _id: true,
15
15
  id: true,
16
16
  virtuals: true,
17
- methods: true
17
+ methods: true,
18
+ statics: true
18
19
  };
19
20
 
20
21
  /**
package/lib/model.js CHANGED
@@ -1099,7 +1099,7 @@ Model.init = function init() {
1099
1099
  return;
1100
1100
  }
1101
1101
 
1102
- return await this.ensureSearchIndexes();
1102
+ return await this.createSearchIndexes();
1103
1103
  };
1104
1104
  const _createCollection = async() => {
1105
1105
  let autoCreate = utils.getOption(
@@ -2092,9 +2092,7 @@ Model.find = function find(conditions, projection, options) {
2092
2092
  };
2093
2093
 
2094
2094
  /**
2095
- * Finds a single document by its _id field. `findById(id)` is almost*
2096
- * equivalent to `findOne({ _id: id })`. If you want to query by a document's
2097
- * `_id`, use `findById()` instead of `findOne()`.
2095
+ * Finds a single document by its _id field. `findById(id)` is equivalent to `findOne({ _id: id })`.
2098
2096
  *
2099
2097
  * The `id` is cast based on the Schema before sending the command.
2100
2098
  *
@@ -2102,11 +2100,6 @@ Model.find = function find(conditions, projection, options) {
2102
2100
  *
2103
2101
  * - `findOne()`
2104
2102
  *
2105
- * \* Except for how it treats `undefined`. If you use `findOne()`, you'll see
2106
- * that `findOne(undefined)` and `findOne({ _id: undefined })` are equivalent
2107
- * to `findOne({})` and return arbitrary documents. However, mongoose
2108
- * translates `findById(undefined)` into `findOne({ _id: null })`.
2109
- *
2110
2103
  * #### Example:
2111
2104
  *
2112
2105
  * // Find the adventure with the given `id`, or `null` if not found
@@ -2131,10 +2124,6 @@ Model.findById = function findById(id, projection, options) {
2131
2124
  throw new MongooseError('Model.findById() no longer accepts a callback');
2132
2125
  }
2133
2126
 
2134
- if (typeof id === 'undefined') {
2135
- id = null;
2136
- }
2137
-
2138
2127
  return this.findOne({ _id: id }, projection, options);
2139
2128
  };
2140
2129
 
@@ -4315,6 +4304,10 @@ Model.validate = async function validate(obj, pathsOrOptions, context) {
4315
4304
  let remaining = paths.size;
4316
4305
 
4317
4306
  return new Promise((resolve, reject) => {
4307
+ if (remaining === 0) {
4308
+ return settle();
4309
+ }
4310
+
4318
4311
  for (const path of paths) {
4319
4312
  const schemaType = schema.path(path);
4320
4313
  if (schemaType == null) {
@@ -4339,13 +4332,17 @@ Model.validate = async function validate(obj, pathsOrOptions, context) {
4339
4332
  }, context, { path: path });
4340
4333
  }
4341
4334
 
4335
+ function settle() {
4336
+ if (error) {
4337
+ reject(error);
4338
+ } else {
4339
+ resolve(obj);
4340
+ }
4341
+ }
4342
+
4342
4343
  function _checkDone() {
4343
4344
  if (--remaining <= 0) {
4344
- if (error) {
4345
- reject(error);
4346
- } else {
4347
- resolve(obj);
4348
- }
4345
+ return settle();
4349
4346
  }
4350
4347
  }
4351
4348
  });
package/lib/query.js CHANGED
@@ -2133,6 +2133,29 @@ Query.prototype._optionsForExec = function(model) {
2133
2133
  }
2134
2134
  }
2135
2135
 
2136
+ if (this._mongooseOptions.populate) {
2137
+ if (options.readPreference) {
2138
+ for (const pop of Object.values(this._mongooseOptions.populate)) {
2139
+ if (pop.options?.readPreference === undefined) {
2140
+ if (!pop.options) {
2141
+ pop.options = {};
2142
+ }
2143
+ pop.options.readPreference = options.readPreference;
2144
+ }
2145
+ }
2146
+ }
2147
+ if (options.readConcern) {
2148
+ for (const pop of Object.values(this._mongooseOptions.populate)) {
2149
+ if (pop.options?.readConcern === undefined) {
2150
+ if (!pop.options) {
2151
+ pop.options = {};
2152
+ }
2153
+ pop.options.readConcern = options.readConcern;
2154
+ }
2155
+ }
2156
+ }
2157
+ }
2158
+
2136
2159
  return options;
2137
2160
  };
2138
2161
 
@@ -4918,24 +4941,6 @@ Query.prototype.populate = function() {
4918
4941
 
4919
4942
  const res = utils.populate.apply(null, args);
4920
4943
 
4921
- // Propagate readConcern and readPreference and lean from parent query,
4922
- // unless one already specified
4923
- if (this.options != null) {
4924
- const readConcern = this.options.readConcern;
4925
- const readPref = this.options.readPreference;
4926
-
4927
- for (const populateOptions of res) {
4928
- if (readConcern != null && (populateOptions && populateOptions.options && populateOptions.options.readConcern) == null) {
4929
- populateOptions.options = populateOptions.options || {};
4930
- populateOptions.options.readConcern = readConcern;
4931
- }
4932
- if (readPref != null && (populateOptions && populateOptions.options && populateOptions.options.readPreference) == null) {
4933
- populateOptions.options = populateOptions.options || {};
4934
- populateOptions.options.readPreference = readPref;
4935
- }
4936
- }
4937
- }
4938
-
4939
4944
  const opts = this._mongooseOptions;
4940
4945
 
4941
4946
  if (opts.lean != null) {
@@ -654,6 +654,8 @@ function cast$elemMatch(val, context) {
654
654
  * For example, `$conditionalHandlers.$all` is the function Mongoose calls to cast `$all` filter operators.
655
655
  *
656
656
  * @property $conditionalHandlers
657
+ * @memberOf SchemaArray
658
+ * @instance
657
659
  * @api public
658
660
  */
659
661
 
@@ -100,7 +100,7 @@ SchemaBigInt.get = SchemaType.get;
100
100
  *
101
101
  * @param {Function} caster
102
102
  * @return {Function}
103
- * @function get
103
+ * @function cast
104
104
  * @static
105
105
  * @api public
106
106
  */
@@ -190,6 +190,8 @@ const $conditionalHandlers = {
190
190
  * For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
191
191
  *
192
192
  * @property $conditionalHandlers
193
+ * @memberOf SchemaBigInt
194
+ * @instance
193
195
  * @api public
194
196
  */
195
197
 
@@ -105,7 +105,7 @@ SchemaBoolean.get = SchemaType.get;
105
105
  *
106
106
  * @param {Function} caster
107
107
  * @return {Function}
108
- * @function get
108
+ * @function cast
109
109
  * @static
110
110
  * @api public
111
111
  */
@@ -242,6 +242,8 @@ const $conditionalHandlers = { ...SchemaType.prototype.$conditionalHandlers };
242
242
  * For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
243
243
  *
244
244
  * @property $conditionalHandlers
245
+ * @memberOf SchemaBoolean
246
+ * @instance
245
247
  * @api public
246
248
  */
247
249
 
@@ -276,6 +276,8 @@ const $conditionalHandlers = {
276
276
  * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
277
277
  *
278
278
  * @property $conditionalHandlers
279
+ * @memberOf SchemaBuffer
280
+ * @instance
279
281
  * @api public
280
282
  */
281
283
 
@@ -111,7 +111,7 @@ SchemaDate.get = SchemaType.get;
111
111
  *
112
112
  * @param {Function} caster
113
113
  * @return {Function}
114
- * @function get
114
+ * @function cast
115
115
  * @static
116
116
  * @api public
117
117
  */
@@ -402,6 +402,8 @@ const $conditionalHandlers = {
402
402
  * For example, `$conditionalHandlers.$gte` is the function Mongoose calls to cast `$gte` filter operators.
403
403
  *
404
404
  * @property $conditionalHandlers
405
+ * @memberOf SchemaDate
406
+ * @instance
405
407
  * @api public
406
408
  */
407
409
 
@@ -227,6 +227,8 @@ const $conditionalHandlers = {
227
227
  * For example, `$conditionalHandlers.$lte` is the function Mongoose calls to cast `$lte` filter operators.
228
228
  *
229
229
  * @property $conditionalHandlers
230
+ * @memberOf SchemaDecimal128
231
+ * @instance
230
232
  * @api public
231
233
  */
232
234
 
@@ -122,6 +122,8 @@ SchemaDocumentArray.prototype.OptionsConstructor = SchemaDocumentArrayOptions;
122
122
  * For example, `$conditionalHandlers.$size` is the function Mongoose calls to cast `$size` filter operators.
123
123
  *
124
124
  * @property $conditionalHandlers
125
+ * @memberOf SchemaDocumentArray
126
+ * @instance
125
127
  * @api public
126
128
  */
127
129
 
@@ -115,7 +115,7 @@ SchemaDouble._defaultCaster = v => {
115
115
  *
116
116
  * @param {Function} caster
117
117
  * @return {Function}
118
- * @function get
118
+ * @function cast
119
119
  * @static
120
120
  * @api public
121
121
  */
@@ -210,6 +210,8 @@ const $conditionalHandlers = {
210
210
  * For example, `$conditionalHandlers.$lt` is the function Mongoose calls to cast `$lt` filter operators.
211
211
  *
212
212
  * @property $conditionalHandlers
213
+ * @memberOf SchemaDouble
214
+ * @instance
213
215
  * @api public
214
216
  */
215
217
 
@@ -119,7 +119,7 @@ SchemaInt32._defaultCaster = v => {
119
119
  *
120
120
  * @param {Function} caster
121
121
  * @return {Function}
122
- * @function get
122
+ * @function cast
123
123
  * @static
124
124
  * @api public
125
125
  */
@@ -214,6 +214,8 @@ const $conditionalHandlers = {
214
214
  * For example, `$conditionalHandlers.$gt` is the function Mongoose calls to cast `$gt` filter operators.
215
215
  *
216
216
  * @property $conditionalHandlers
217
+ * @memberOf SchemaInt32
218
+ * @instance
217
219
  * @api public
218
220
  */
219
221
 
@@ -93,7 +93,7 @@ SchemaNumber._cast = castNumber;
93
93
  *
94
94
  * @param {Function} caster
95
95
  * @return {Function}
96
- * @function get
96
+ * @function cast
97
97
  * @static
98
98
  * @api public
99
99
  */
@@ -418,6 +418,8 @@ const $conditionalHandlers = {
418
418
  * For example, `$conditionalHandlers.$gte` is the function Mongoose calls to cast `$gte` filter operators.
419
419
  *
420
420
  * @property $conditionalHandlers
421
+ * @memberOf SchemaNumber
422
+ * @instance
421
423
  * @api public
422
424
  */
423
425
 
@@ -143,7 +143,7 @@ SchemaObjectId._cast = castObjectId;
143
143
  *
144
144
  * @param {Function} caster
145
145
  * @return {Function}
146
- * @function get
146
+ * @function cast
147
147
  * @static
148
148
  * @api public
149
149
  */
@@ -273,6 +273,8 @@ const $conditionalHandlers = {
273
273
  * For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
274
274
  *
275
275
  * @property $conditionalHandlers
276
+ * @memberOf SchemaObjectId
277
+ * @instance
276
278
  * @api public
277
279
  */
278
280
 
@@ -310,6 +312,7 @@ function resetId(v) {
310
312
  * @param [options]
311
313
  * @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
312
314
  * @returns {Object} JSON schema properties
315
+ * @api public
313
316
  */
314
317
 
315
318
  SchemaObjectId.prototype.toJSONSchema = function toJSONSchema(options) {
@@ -75,7 +75,7 @@ SchemaString._cast = castString;
75
75
  *
76
76
  * @param {Function} caster
77
77
  * @return {Function}
78
- * @function get
78
+ * @function cast
79
79
  * @static
80
80
  * @api public
81
81
  */
@@ -381,7 +381,7 @@ SchemaString.prototype.trim = function(shouldTrim) {
381
381
  *
382
382
  * #### Example:
383
383
  *
384
- * const schema = new Schema({ postalCode: { type: String, minlength: 5 })
384
+ * const schema = new Schema({ postalCode: { type: String, minLength: 5 })
385
385
  * const Address = db.model('Address', schema)
386
386
  * const address = new Address({ postalCode: '9512' })
387
387
  * address.save(function (err) {
@@ -392,8 +392,8 @@ SchemaString.prototype.trim = function(shouldTrim) {
392
392
  *
393
393
  * // custom error messages
394
394
  * // We can also use the special {MINLENGTH} token which will be replaced with the minimum allowed length
395
- * const minlength = [5, 'The value of path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).'];
396
- * const schema = new Schema({ postalCode: { type: String, minlength: minlength })
395
+ * const minLength = [5, 'The value of path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).'];
396
+ * const schema = new Schema({ postalCode: { type: String, minLength: minLength })
397
397
  * const Address = mongoose.model('Address', schema);
398
398
  * const address = new Address({ postalCode: '9512' });
399
399
  * address.validate(function (err) {
@@ -665,6 +665,8 @@ const $conditionalHandlers = {
665
665
  * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
666
666
  *
667
667
  * @property $conditionalHandlers
668
+ * @memberOf SchemaString
669
+ * @instance
668
670
  * @api public
669
671
  */
670
672
 
@@ -158,6 +158,8 @@ $conditionalHandlers.$exists = $exists;
158
158
  * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
159
159
  *
160
160
  * @property $conditionalHandlers
161
+ * @memberOf SchemaSubdocument
162
+ * @instance
161
163
  * @api public
162
164
  */
163
165
 
@@ -263,6 +263,8 @@ const $conditionalHandlers = {
263
263
  * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
264
264
  *
265
265
  * @property $conditionalHandlers
266
+ * @memberOf SchemaUUID
267
+ * @instance
266
268
  * @api public
267
269
  */
268
270
 
package/lib/schemaType.js CHANGED
@@ -1643,6 +1643,8 @@ function handle$in(val, context) {
1643
1643
  * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
1644
1644
  *
1645
1645
  * @property $conditionalHandlers
1646
+ * @memberOf SchemaType
1647
+ * @instance
1646
1648
  * @api public
1647
1649
  */
1648
1650
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.17.0",
4
+ "version": "8.17.2",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -29,8 +29,8 @@
29
29
  "sift": "17.1.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@babel/core": "7.27.7",
33
- "@babel/preset-env": "7.27.2",
32
+ "@babel/core": "7.28.0",
33
+ "@babel/preset-env": "7.28.0",
34
34
  "@mongodb-js/mongodb-downloader": "^0.4.2",
35
35
  "@typescript-eslint/eslint-plugin": "^8.19.1",
36
36
  "@typescript-eslint/parser": "^8.19.1",
@@ -42,7 +42,7 @@
42
42
  "babel-loader": "8.2.5",
43
43
  "broken-link-checker": "^0.7.8",
44
44
  "buffer": "^5.6.0",
45
- "cheerio": "1.1.0",
45
+ "cheerio": "1.1.2",
46
46
  "crypto-browserify": "3.12.1",
47
47
  "dox": "1.0.0",
48
48
  "eslint": "8.57.1",
@@ -69,7 +69,7 @@
69
69
  "tsd": "0.32.0",
70
70
  "typescript": "5.8.3",
71
71
  "uuid": "11.1.0",
72
- "webpack": "5.99.9"
72
+ "webpack": "5.101.0"
73
73
  },
74
74
  "directories": {
75
75
  "lib": "./lib/mongoose"
@@ -256,12 +256,17 @@ declare module 'mongoose' {
256
256
  set(value: string | Record<string, any>): this;
257
257
 
258
258
  /** The return value of this method is used in calls to JSON.stringify(doc). */
259
- toJSON(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>, TSchemaOptions>;
260
- toJSON(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<Default__v<Require_id<DocType>, TSchemaOptions>>;
261
- toJSON(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<Default__v<Require_id<DocType>, TSchemaOptions>>;
262
- toJSON(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Default__v<Require_id<DocType>, TSchemaOptions>>>;
263
- toJSON(options: ToObjectOptions & { flattenMaps: false }): Default__v<Require_id<DocType>, TSchemaOptions>;
264
- toJSON(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType>, TSchemaOptions>>;
259
+ toJSON(options: ToObjectOptions & { versionKey: false, virtuals: true, flattenObjectIds: true }): Omit<ObjectIdToString<FlattenMaps<Require_id<DocType & TVirtuals>>>, '__v'>;
260
+ toJSON(options: ToObjectOptions & { virtuals: true, flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Default__v<Require_id<DocType & TVirtuals>, ResolveSchemaOptions<TSchemaOptions>>>>;
261
+ toJSON(options: ToObjectOptions & { versionKey: false, virtuals: true }): Omit<Require_id<DocType & TVirtuals>, '__v'>;
262
+ toJSON(options: ToObjectOptions & { versionKey: false, flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Omit<Require_id<DocType>, '__v'>>>;
263
+ toJSON(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>, ResolveSchemaOptions<TSchemaOptions>>;
264
+ toJSON(options: ToObjectOptions & { versionKey: false }): Omit<Require_id<DocType & TVirtuals>, '__v'>;
265
+ toJSON(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>>;
266
+ toJSON(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>>;
267
+ toJSON(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>>>;
268
+ toJSON(options: ToObjectOptions & { flattenMaps: false }): Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>;
269
+ toJSON(options: ToObjectOptions & { flattenMaps: false, flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>>;
265
270
 
266
271
  toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<T>;
267
272
  toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<T>;
@@ -270,9 +275,15 @@ declare module 'mongoose' {
270
275
  toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options: ToObjectOptions & { flattenMaps: false, flattenObjectIds: true }): ObjectIdToString<T>;
271
276
 
272
277
  /** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */
273
- toObject(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>, TSchemaOptions>;
274
- toObject(options?: ToObjectOptions): Default__v<Require_id<DocType>, TSchemaOptions>;
275
- toObject<T>(options?: ToObjectOptions): Default__v<Require_id<T>, TSchemaOptions>;
278
+ toObject(options: ToObjectOptions & { versionKey: false, virtuals: true, flattenObjectIds: true }): Omit<ObjectIdToString<Require_id<DocType & TVirtuals>>, '__v'>;
279
+ toObject(options: ToObjectOptions & { virtuals: true, flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType & TVirtuals>, ResolveSchemaOptions<TSchemaOptions>>>;
280
+ toObject(options: ToObjectOptions & { versionKey: false, flattenObjectIds: true }): Omit<ObjectIdToString<Require_id<DocType & TVirtuals>>, '__v'>;
281
+ toObject(options: ToObjectOptions & { versionKey: false, virtuals: true }): Omit<Require_id<DocType & TVirtuals>, '__v'>;
282
+ toObject(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>, ResolveSchemaOptions<TSchemaOptions>>;
283
+ toObject(options: ToObjectOptions & { versionKey: false }): Omit<Require_id<DocType & TVirtuals>, '__v'>;
284
+ toObject(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType & TVirtuals>, ResolveSchemaOptions<TSchemaOptions>>>;
285
+ toObject(options?: ToObjectOptions): Default__v<Require_id<DocType>, ResolveSchemaOptions<TSchemaOptions>>;
286
+ toObject<T>(options?: ToObjectOptions): Default__v<Require_id<T>, ResolveSchemaOptions<TSchemaOptions>>;
276
287
 
277
288
  /** Clears the modified state on the specified path. */
278
289
  unmarkModified<T extends keyof DocType>(path: T): void;
package/types/index.d.ts CHANGED
@@ -140,9 +140,21 @@ declare module 'mongoose' {
140
140
  ? IfAny<U, T & { _id: Types.ObjectId }, T & Required<{ _id: U }>>
141
141
  : T & { _id: Types.ObjectId };
142
142
 
143
- export type Default__v<T, TSchemaOptions = {}> = TSchemaOptions extends { versionKey: false } ? T : T extends { __v?: infer U }
143
+ export type Default__v<T, TSchemaOptions = {}> = TSchemaOptions extends { versionKey: false }
144
144
  ? T
145
- : T & { __v: number };
145
+ : TSchemaOptions extends { versionKey: infer VK }
146
+ ? (
147
+ // If VK is a *literal* string, add that property
148
+ T & {
149
+ [K in VK as K extends string
150
+ ? (string extends K ? never : K) // drop if wide string
151
+ : never
152
+ ]: number
153
+ }
154
+ )
155
+ : T extends { __v?: infer U }
156
+ ? T
157
+ : T & { __v: number };
146
158
 
147
159
  /** Helper type for getting the hydrated document type from the raw document type. The hydrated document type is what `new MyModel()` returns. */
148
160
  export type HydratedDocument<
@@ -704,9 +716,9 @@ declare module 'mongoose' {
704
716
  [K in keyof T]?: T[K] extends Record<string, any> ? Projector<T[K], Element> | Element : Element;
705
717
  }
706
718
  : Element;
707
- type _IDType = { _id?: boolean | 1 | 0 };
719
+ type _IDType = { _id?: boolean | number };
708
720
  export type InclusionProjection<T> = IsItRecordAndNotAny<T> extends true
709
- ? Omit<Projector<WithLevel1NestedPaths<T>, true | 1>, '_id'> & _IDType
721
+ ? Omit<Projector<WithLevel1NestedPaths<T>, boolean | number>, '_id'> & _IDType
710
722
  : AnyObject;
711
723
  export type ExclusionProjection<T> = IsItRecordAndNotAny<T> extends true
712
724
  ? Omit<Projector<WithLevel1NestedPaths<T>, false | 0>, '_id'> & _IDType
@@ -207,9 +207,11 @@ declare module 'mongoose' {
207
207
 
208
208
  /** If set, Mongoose will add a custom validator that ensures the given string's `length` is at least the given number. */
209
209
  minlength?: number | [number, string] | readonly [number, string];
210
+ minLength?: number | [number, string] | readonly [number, string];
210
211
 
211
212
  /** If set, Mongoose will add a custom validator that ensures the given string's `length` is at most the given number. */
212
213
  maxlength?: number | [number, string] | readonly [number, string];
214
+ maxLength?: number | [number, string] | readonly [number, string];
213
215
 
214
216
  [other: string]: any;
215
217