mongoose 9.10.3 → 9.11.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.
@@ -2,6 +2,9 @@
2
2
 
3
3
  const get = require('../get');
4
4
  const utils = require('../../utils');
5
+
6
+ const simpleCollation = Object.freeze({ locale: 'simple' });
7
+
5
8
  /**
6
9
  * Given a Mongoose index definition (key + options objects) and a MongoDB server
7
10
  * index definition, determine if the two indexes are equal.
@@ -61,14 +64,13 @@ module.exports = function isIndexEqual(schemaIndexKeysObject, options, dbIndex)
61
64
  continue;
62
65
  }
63
66
  if (key === 'collation') {
64
- if (options[key] == null || dbIndex[key] == null) {
65
- return options[key] == null && dbIndex[key] == null;
66
- }
67
- const definedKeys = Object.keys(options.collation);
68
- const schemaCollation = options.collation;
69
- const dbCollation = dbIndex.collation;
70
- for (const opt of definedKeys) {
71
- if (get(schemaCollation, opt) !== get(dbCollation, opt)) {
67
+ // No collation is equivalent to { locale: 'simple' }. MongoDB server 9
68
+ // reports { locale: 'simple' } for indexes created with no collation,
69
+ // older versions omit it.
70
+ const schemaCollation = options.collation ?? simpleCollation;
71
+ const dbCollation = dbIndex.collation ?? simpleCollation;
72
+ for (const opt of Object.keys(schemaCollation)) {
73
+ if (schemaCollation[opt] !== dbCollation[opt]) {
72
74
  return false;
73
75
  }
74
76
  }
@@ -97,7 +97,15 @@ function _castExpression(val, schema, strictQuery) {
97
97
  val.$ifNull.map(v => _castExpression(v, schema, strictQuery));
98
98
  } else if (val.$switch != null) {
99
99
  if (Array.isArray(val.$switch.branches)) {
100
- val.$switch.branches = val.$switch.branches.map(v => _castExpression(v, schema, strictQuery));
100
+ for (const branch of val.$switch.branches) {
101
+ if (branch?.case != null) {
102
+ branch.case = _castExpression(branch.case, schema, strictQuery);
103
+ }
104
+ if (branch?.then != null) {
105
+ branch.then = _castExpression(branch.then, schema, strictQuery);
106
+ }
107
+ omitUndefined(branch);
108
+ }
101
109
  }
102
110
  if ('default' in val.$switch) {
103
111
  val.$switch.default = _castExpression(val.$switch.default, schema, strictQuery);
package/lib/model.js CHANGED
@@ -4769,7 +4769,10 @@ async function _populatePath(model, docs, populateOptions) {
4769
4769
  // Get the assigned (filtered) children from parent docs
4770
4770
  const childDocsToPopulate = [];
4771
4771
  for (const doc of mod.docs) {
4772
- const childVal = doc.$__ != null ? doc.get(mod.options.path) : doc[mod.options.path];
4772
+ // `utils.getValue()` rather than a bracket lookup, because `mod.options.path` may be
4773
+ // a dotted path like 'children.child', which a lean result does not store as a
4774
+ // single key.
4775
+ const childVal = doc.$__ != null ? doc.get(mod.options.path) : utils.getValue(mod.options.path, doc);
4773
4776
  if (Array.isArray(childVal)) {
4774
4777
  childDocsToPopulate.push(...childVal);
4775
4778
  } else if (childVal != null) {
package/lib/query.js CHANGED
@@ -2563,6 +2563,35 @@ Query.prototype.find = function(conditions) {
2563
2563
  return this;
2564
2564
  };
2565
2565
 
2566
+ /**
2567
+ * Executes the query as a `find()` and also runs a `countDocuments()` query
2568
+ * on the same filter, returning `[documents, count]`. The count ignores
2569
+ * `skip` and `limit` so that it returns the total number of matching documents.
2570
+ *
2571
+ * #### Example:
2572
+ *
2573
+ * const query = Adventure.find({ type: 'animal' }).sort({ name: 1 }).limit(10);
2574
+ * const [adventures, total] = await query.findAndCount();
2575
+ *
2576
+ * @return {Promise<Array>} a promise that resolves to `[documents, total]`
2577
+ * @api public
2578
+ */
2579
+
2580
+ Query.prototype.findAndCount = async function findAndCount() {
2581
+ if (this.options.sort == null) {
2582
+ throw new MongooseError('Query.prototype.findAndCount() requires sort. Use `sort()` to set a sort order before calling `findAndCount()`.');
2583
+ }
2584
+ if (this.options.limit == null) {
2585
+ throw new MongooseError('Query.prototype.findAndCount() requires limit. Use `limit()` to set a limit before calling `findAndCount()`.');
2586
+ }
2587
+
2588
+ this.op = 'find';
2589
+
2590
+ const countQuery = this.clone().countDocuments().skip(0).limit(null);
2591
+
2592
+ return Promise.all([this.exec(), countQuery.exec()]);
2593
+ };
2594
+
2566
2595
  /**
2567
2596
  * Merges another Query or conditions object into this one.
2568
2597
  *
@@ -65,7 +65,6 @@ function SchemaDocumentArray(key, schema, options, schemaOptions, parentSchema)
65
65
  $parentSchemaType,
66
66
  Constructor
67
67
  });
68
-
69
68
  SchemaArray.call(this, key, embeddedSchemaType, options, null, parentSchema);
70
69
 
71
70
  this.schema = schema;
@@ -234,8 +233,16 @@ SchemaDocumentArray.prototype.doValidate = async function doValidate(array, scop
234
233
  // lazy load
235
234
  MongooseDocumentArray || (MongooseDocumentArray = require('../types/documentArray'));
236
235
 
237
- await SchemaType.prototype.doValidate.call(this, array, scope);
236
+ let schemaTypeError;
237
+ try {
238
+ await SchemaType.prototype.doValidate.call(this, array, scope);
239
+ } catch (err) {
240
+ schemaTypeError = err;
241
+ }
238
242
  if (options?.updateValidator) {
243
+ if (schemaTypeError != null) {
244
+ throw schemaTypeError;
245
+ }
239
246
  return;
240
247
  }
241
248
  if (!utils.isMongooseDocumentArray(array)) {
@@ -258,14 +265,29 @@ SchemaDocumentArray.prototype.doValidate = async function doValidate(array, scop
258
265
  doc = array[i] = new Constructor(doc, array, undefined, undefined, i);
259
266
  }
260
267
 
261
- if (options?.validateModifiedOnly && !doc.$isModified()) {
268
+ if (options?.validateModifiedOnly && !doc.$isNew && !doc.$isModified()) {
262
269
  continue;
263
270
  }
264
271
 
265
- promises.push(doc.validate(null, options));
272
+ const subdocOptions = doc.$isNew && options?.validateModifiedOnly ?
273
+ { ...options, validateModifiedOnly: false } :
274
+ options;
275
+ promises.push(doc.validate(null, subdocOptions));
266
276
  }
267
277
 
268
- await Promise.all(promises);
278
+ let subdocumentError;
279
+ try {
280
+ await Promise.all(promises);
281
+ } catch (err) {
282
+ subdocumentError = err;
283
+ }
284
+
285
+ if (schemaTypeError != null) {
286
+ throw schemaTypeError;
287
+ }
288
+ if (subdocumentError != null) {
289
+ throw subdocumentError;
290
+ }
269
291
  };
270
292
 
271
293
  /**
@@ -281,15 +303,11 @@ SchemaDocumentArray.prototype.doValidate = async function doValidate(array, scop
281
303
 
282
304
  SchemaDocumentArray.prototype.doValidateSync = function(array, scope, options) {
283
305
  const schemaTypeError = SchemaType.prototype.doValidateSync.call(this, array, scope);
284
- if (schemaTypeError != null) {
285
- return schemaTypeError;
286
- }
287
-
288
306
  const count = array?.length;
289
- let resultError = null;
307
+ let resultError = schemaTypeError;
290
308
 
291
309
  if (!count) {
292
- return;
310
+ return resultError;
293
311
  }
294
312
 
295
313
  // handle sparse arrays, do not use array.forEach which does not
@@ -310,11 +328,14 @@ SchemaDocumentArray.prototype.doValidateSync = function(array, scope, options) {
310
328
  doc = array[i] = new Constructor(doc, array, undefined, undefined, i);
311
329
  }
312
330
 
313
- if (options?.validateModifiedOnly && !doc.$isModified()) {
331
+ if (options?.validateModifiedOnly && !doc.$isNew && !doc.$isModified()) {
314
332
  continue;
315
333
  }
316
334
 
317
- const subdocValidateError = doc.$__validateSync(options);
335
+ const subdocOptions = doc.$isNew && options?.validateModifiedOnly ?
336
+ { ...options, validateModifiedOnly: false } :
337
+ options;
338
+ const subdocValidateError = doc.$__validateSync(subdocOptions);
318
339
 
319
340
  if (subdocValidateError && resultError == null) {
320
341
  resultError = subdocValidateError;
@@ -108,9 +108,41 @@ SchemaDocumentArrayElement.prototype.doValidate = async function doValidate(valu
108
108
  value = new Constructor(value, scope, null, null, options?.index ?? null);
109
109
  }
110
110
 
111
+ // The parent document array validates each of its subdocuments, so when it
112
+ // already did, this element's own validators are all that is left to run.
113
+ if (options?.skipSubdocumentValidation) {
114
+ if (options.skipSchemaValidators) {
115
+ return;
116
+ }
117
+ return SchemaType.prototype.doValidate.call(this, value, scope, options);
118
+ }
119
+
111
120
  return SchemaSubdocument.prototype.doValidate.call(this, value, scope, options);
112
121
  };
113
122
 
123
+ /**
124
+ * Synchronous validation on this individual array element
125
+ *
126
+ * @api private
127
+ */
128
+
129
+ SchemaDocumentArrayElement.prototype.doValidateSync = function doValidateSync(value, scope, options) {
130
+ const Constructor = getConstructor(this.Constructor, value);
131
+
132
+ if (value && !(value instanceof Constructor)) {
133
+ value = new Constructor(value, scope, null, null, options?.index ?? null);
134
+ }
135
+
136
+ if (options?.skipSubdocumentValidation) {
137
+ if (options.skipSchemaValidators) {
138
+ return;
139
+ }
140
+ return SchemaType.prototype.doValidateSync.call(this, value, scope, options);
141
+ }
142
+
143
+ return SchemaSubdocument.prototype.doValidateSync.call(this, value, scope, options);
144
+ };
145
+
114
146
  /**
115
147
  * Clone the current SchemaType
116
148
  *
@@ -544,11 +544,13 @@ const methods = {
544
544
  if (isBsonType(obj, 'ObjectId')) {
545
545
  obj = obj.toString();
546
546
  }
547
+ // Compare dates by timestamp like `addToSet()` does, so `pull()` works on date arrays
548
+ const isDate = obj instanceof Date;
547
549
 
548
550
  fromIndex = fromIndex == null ? 0 : fromIndex;
549
551
  const len = this.length;
550
552
  for (let i = fromIndex; i < len; ++i) {
551
- if (obj == this[i]) {
553
+ if (obj == this[i] || (isDate && this[i] instanceof Date && +obj === +this[i])) {
552
554
  return i;
553
555
  }
554
556
  }
package/lib/types/map.js CHANGED
@@ -4,6 +4,7 @@ const Mixed = require('../schema/mixed');
4
4
  const MongooseError = require('../error/mongooseError');
5
5
  const clone = require('../helpers/clone');
6
6
  const deepEqual = require('../utils').deepEqual;
7
+ const isMongooseArray = require('../utils').isMongooseArray;
7
8
  const getConstructorName = require('../helpers/getConstructorName');
8
9
  const handleSpreadDoc = require('../helpers/document/handleSpreadDoc');
9
10
  const util = require('util');
@@ -160,6 +161,11 @@ class MongooseMap extends Map {
160
161
  if (parent?.$__ != null && !deepEqual(value, priorVal)) {
161
162
  const path = fullPath.call(this);
162
163
  parent.markModified(path);
164
+ // Replacing the whole array means later push(), pull() or addToSet() calls must not be sent as
165
+ // atomics against the array that was in the database, same as Document#$set re: gh-1126
166
+ if (isMongooseArray(value)) {
167
+ value._registerAtomic('$set', value);
168
+ }
163
169
  // If overwriting the full document array or subdoc, make sure to clean up any paths that were modified
164
170
  // before re: #15108
165
171
  if (this.$__schemaType.$isMongooseDocumentArray || this.$__schemaType.$isSingleNested) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "9.10.3",
4
+ "version": "9.11.0",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -22,16 +22,16 @@
22
22
  "dependencies": {
23
23
  "@standard-schema/spec": "^1.1.0",
24
24
  "kareem": "3.4.0",
25
- "mongodb": "~7.6",
25
+ "mongodb": "~7.7",
26
26
  "mpath": "0.9.0",
27
27
  "mquery": "6.0.0",
28
28
  "ms": "2.1.3",
29
29
  "sift": "17.1.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@ark/attest": "0.56.3",
32
+ "@ark/attest": "0.56.5",
33
33
  "@eslint/js": "^9.39.3",
34
- "@mongodb-js/mongodb-downloader": "^1.0.0",
34
+ "@mongodb-js/mongodb-downloader": "^2.0.2",
35
35
  "@types/node": "^20.19.0",
36
36
  "acquit": "1.4.0",
37
37
  "acquit-ignore": "0.2.2",
@@ -40,7 +40,7 @@
40
40
  "c8": "12.0.0",
41
41
  "cheerio": "1.2.0",
42
42
  "dox": "1.0.0",
43
- "eslint": "10.9.1",
43
+ "eslint": "10.11.0",
44
44
  "eslint-plugin-mocha-no-only": "1.2.0",
45
45
  "express": "5.2.1",
46
46
  "fs-extra": "~11.4.0",
@@ -50,13 +50,13 @@
50
50
  "linkinator": "8.x",
51
51
  "lodash.isequal": "4.5.0",
52
52
  "lodash.isequalwith": "4.4.0",
53
- "markdownlint-cli2": "0.23.2",
54
- "marked": "18.0.11",
53
+ "markdownlint-cli2": "0.23.3",
54
+ "marked": "18.0.14",
55
55
  "mkdirp": "^3.0.1",
56
- "mocha": "12.0.0-rc.6",
57
- "moment": "2.30.1",
56
+ "mocha": "12.0.2",
57
+ "moment": "2.31.0",
58
58
  "mongodb-client-encryption": "^7.2.0",
59
- "mongodb-memory-server": "11.2.0",
59
+ "mongodb-memory-server": "11.3.0",
60
60
  "mongodb-runner": "^6.0.0",
61
61
  "ncp": "^2.0.0",
62
62
  "pug": "3.0.4",
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://tstyche.org/schemas/config.json",
3
+ "checkDeclarationFiles": false,
4
+ "checkSuppressedErrors": false,
5
+ "testFileMatch": [
6
+ "test/types/*.test.*",
7
+ "test/types/**/*.test.*"
8
+ ]
9
+ }
@@ -203,7 +203,7 @@ declare module 'mongoose' {
203
203
  ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>
204
204
  >,
205
205
  TSchema,
206
- ObtainSchemaGeneric<TSchema, 'TLeanResultType'>
206
+ Default__v<Require_id<ObtainSchemaGeneric<TSchema, 'TLeanResultType'>>>
207
207
  > & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
208
208
  model<T, U, TQueryHelpers = {}>(
209
209
  name: string,
@@ -141,7 +141,9 @@ declare module 'mongoose' {
141
141
  this,
142
142
  TQueryHelpers,
143
143
  DocType,
144
- 'deleteOne'
144
+ 'deleteOne',
145
+ Record<string, never>,
146
+ Default__v<Require_id<DocType>>
145
147
  >;
146
148
 
147
149
  /**
package/types/index.d.ts CHANGED
@@ -104,7 +104,7 @@ declare module 'mongoose' {
104
104
  ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>
105
105
  >,
106
106
  TSchema,
107
- ObtainSchemaGeneric<TSchema, 'TLeanResultType'>
107
+ Default__v<Require_id<ObtainSchemaGeneric<TSchema, 'TLeanResultType'>>>
108
108
  > & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
109
109
 
110
110
  export function model<T>(name: string, schema?: Schema<T, any, any> | Schema<T & Document, any, any>, collection?: string, options?: CompileModelOptions): Model<T>;
package/types/models.d.ts CHANGED
@@ -228,7 +228,7 @@ declare module 'mongoose' {
228
228
  TVirtuals = {},
229
229
  THydratedDocumentType = HydratedDocument<TRawDocType, TVirtuals & TInstanceMethods, TQueryHelpers, TVirtuals>,
230
230
  TSchema = any,
231
- TLeanResultType = TRawDocType> extends
231
+ TLeanResultType = Default__v<Require_id<TRawDocType>>> extends
232
232
  NodeJS.EventEmitter,
233
233
  IndexManager,
234
234
  SessionStarter {
@@ -455,7 +455,8 @@ declare module 'mongoose' {
455
455
  TQueryHelpers,
456
456
  TLeanResultType,
457
457
  'findOne',
458
- TInstanceMethods & TVirtuals
458
+ TInstanceMethods & TVirtuals,
459
+ ApplyProjection<TLeanResultType, Projection>
459
460
  >;
460
461
  findById<ResultDoc = THydratedDocumentType>(
461
462
  id: any,
@@ -505,7 +506,8 @@ declare module 'mongoose' {
505
506
  TQueryHelpers,
506
507
  TLeanResultType,
507
508
  'findOne',
508
- TInstanceMethods & TVirtuals
509
+ TInstanceMethods & TVirtuals,
510
+ ApplyProjection<TLeanResultType, Projection>
509
511
  >;
510
512
  findOne<const Projection extends ProjectionType<TRawDocType>>(
511
513
  filter: QueryFilter<TRawDocType>,
@@ -517,7 +519,8 @@ declare module 'mongoose' {
517
519
  TQueryHelpers,
518
520
  TLeanResultType,
519
521
  'findOne',
520
- TInstanceMethods & TVirtuals
522
+ TInstanceMethods & TVirtuals,
523
+ ApplyProjection<TLeanResultType, Projection>
521
524
  >;
522
525
  findOne<const Projection extends ProjectionType<TRawDocType>>(
523
526
  filter: QueryFilter<TRawDocType>,
@@ -529,7 +532,8 @@ declare module 'mongoose' {
529
532
  TQueryHelpers,
530
533
  TLeanResultType,
531
534
  'findOne',
532
- TInstanceMethods & TVirtuals
535
+ TInstanceMethods & TVirtuals,
536
+ ApplyProjection<TLeanResultType, Projection>
533
537
  >;
534
538
  findOne<const Projection extends ProjectionType<TRawDocType>>(
535
539
  filter: QueryFilter<TRawDocType>,
@@ -541,7 +545,8 @@ declare module 'mongoose' {
541
545
  TQueryHelpers,
542
546
  TLeanResultType,
543
547
  'findOne',
544
- TInstanceMethods & TVirtuals
548
+ TInstanceMethods & TVirtuals,
549
+ ApplyProjection<TLeanResultType, Projection>
545
550
  >;
546
551
  findOne<ResultDoc = THydratedDocumentType>(
547
552
  filter: QueryFilter<TRawDocType>,
@@ -850,7 +855,8 @@ declare module 'mongoose' {
850
855
  TQueryHelpers,
851
856
  TLeanResultType,
852
857
  'find',
853
- TInstanceMethods & TVirtuals
858
+ TInstanceMethods & TVirtuals,
859
+ ApplyProjection<TLeanResultType, Projection>
854
860
  >;
855
861
  find<const Projection extends ProjectionType<TRawDocType>>(
856
862
  filter: QueryFilter<TRawDocType>,
@@ -862,7 +868,8 @@ declare module 'mongoose' {
862
868
  TQueryHelpers,
863
869
  TLeanResultType,
864
870
  'find',
865
- TInstanceMethods & TVirtuals
871
+ TInstanceMethods & TVirtuals,
872
+ ApplyProjection<TLeanResultType, Projection>
866
873
  >;
867
874
  find<const Projection extends ProjectionType<TRawDocType>>(
868
875
  filter: QueryFilter<TRawDocType>,
@@ -874,7 +881,8 @@ declare module 'mongoose' {
874
881
  TQueryHelpers,
875
882
  TLeanResultType,
876
883
  'find',
877
- TInstanceMethods & TVirtuals
884
+ TInstanceMethods & TVirtuals,
885
+ ApplyProjection<TLeanResultType, Projection>
878
886
  >;
879
887
  find<const Projection extends ProjectionType<TRawDocType>>(
880
888
  filter: QueryFilter<TRawDocType>,
@@ -886,14 +894,15 @@ declare module 'mongoose' {
886
894
  TQueryHelpers,
887
895
  TLeanResultType,
888
896
  'find',
889
- TInstanceMethods & TVirtuals
897
+ TInstanceMethods & TVirtuals,
898
+ ApplyProjection<TLeanResultType, Projection>
890
899
  >;
891
900
  find<ResultDoc = THydratedDocumentType>(
892
901
  filter: QueryFilter<TRawDocType>,
893
902
  projection: ProjectionType<TRawDocType> | null | undefined,
894
903
  options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
895
904
  ): QueryWithHelpers<
896
- GetLeanResultType<TRawDocType, TRawDocType[], 'find'>,
905
+ GetLeanResultType<TLeanResultType, TRawDocType[], 'find'>,
897
906
  ResultDoc,
898
907
  TQueryHelpers,
899
908
  TLeanResultType,
@@ -905,7 +914,7 @@ declare module 'mongoose' {
905
914
  projection: ProjectionType<TRawDocType> | null | undefined,
906
915
  options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
907
916
  ): QueryWithHelpers<
908
- GetLeanResultType<TRawDocType, TRawDocType[], 'find'>,
917
+ GetLeanResultType<TLeanResultType, TRawDocType[], 'find'>,
909
918
  THydratedDocumentType,
910
919
  TQueryHelpers,
911
920
  TLeanResultType,
@@ -959,7 +968,7 @@ declare module 'mongoose' {
959
968
  filter: QueryFilter<TRawDocType>,
960
969
  projection: ProjectionType<TRawDocType> | null | undefined,
961
970
  options: QueryOptions<TRawDocType> & { sort: any; limit: number; lean: true } & mongodb.Abortable
962
- ): Promise<[GetLeanResultType<TRawDocType, TRawDocType[], 'find'>, number]>;
971
+ ): Promise<[GetLeanResultType<TLeanResultType, TRawDocType[], 'find'>, number]>;
963
972
  findAndCount<ResultDoc = THydratedDocumentType>(
964
973
  filter: QueryFilter<TRawDocType>,
965
974
  projection: ProjectionType<TRawDocType> | null | undefined,
@@ -981,7 +990,8 @@ declare module 'mongoose' {
981
990
  TQueryHelpers,
982
991
  TLeanResultType,
983
992
  'findOneAndDelete',
984
- TInstanceMethods & TVirtuals
993
+ TInstanceMethods & TVirtuals,
994
+ ApplyProjection<TLeanResultType, Projection>
985
995
  >;
986
996
  findByIdAndDelete<const Projection extends ProjectionType<TRawDocType>>(
987
997
  id: mongodb.ObjectId | any,
@@ -992,7 +1002,8 @@ declare module 'mongoose' {
992
1002
  TQueryHelpers,
993
1003
  TLeanResultType,
994
1004
  'findOneAndDelete',
995
- TInstanceMethods & TVirtuals
1005
+ TInstanceMethods & TVirtuals,
1006
+ ApplyProjection<TLeanResultType, Projection>
996
1007
  >;
997
1008
  findByIdAndDelete<ResultDoc = THydratedDocumentType>(
998
1009
  id: mongodb.ObjectId | any,
@@ -1062,7 +1073,8 @@ declare module 'mongoose' {
1062
1073
  TQueryHelpers,
1063
1074
  TLeanResultType,
1064
1075
  'findOneAndUpdate',
1065
- TInstanceMethods & TVirtuals
1076
+ TInstanceMethods & TVirtuals,
1077
+ ApplyProjection<TLeanResultType, Projection>
1066
1078
  >;
1067
1079
  findByIdAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
1068
1080
  id: mongodb.ObjectId | any,
@@ -1074,7 +1086,8 @@ declare module 'mongoose' {
1074
1086
  TQueryHelpers,
1075
1087
  TLeanResultType,
1076
1088
  'findOneAndUpdate',
1077
- TInstanceMethods & TVirtuals
1089
+ TInstanceMethods & TVirtuals,
1090
+ ApplyProjection<TLeanResultType, Projection>
1078
1091
  >;
1079
1092
  findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
1080
1093
  filter: QueryFilter<TRawDocType>,
@@ -1171,7 +1184,8 @@ declare module 'mongoose' {
1171
1184
  TQueryHelpers,
1172
1185
  TLeanResultType,
1173
1186
  'findOneAndDelete',
1174
- TInstanceMethods & TVirtuals
1187
+ TInstanceMethods & TVirtuals,
1188
+ ApplyProjection<TLeanResultType, Projection>
1175
1189
  >;
1176
1190
  findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
1177
1191
  filter: QueryFilter<TRawDocType>,
@@ -1182,7 +1196,8 @@ declare module 'mongoose' {
1182
1196
  TQueryHelpers,
1183
1197
  TLeanResultType,
1184
1198
  'findOneAndDelete',
1185
- TInstanceMethods & TVirtuals
1199
+ TInstanceMethods & TVirtuals,
1200
+ ApplyProjection<TLeanResultType, Projection>
1186
1201
  >;
1187
1202
  findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
1188
1203
  filter: QueryFilter<TRawDocType>,
@@ -1193,7 +1208,8 @@ declare module 'mongoose' {
1193
1208
  TQueryHelpers,
1194
1209
  TLeanResultType,
1195
1210
  'findOneAndDelete',
1196
- TInstanceMethods & TVirtuals
1211
+ TInstanceMethods & TVirtuals,
1212
+ ApplyProjection<TLeanResultType, Projection>
1197
1213
  >;
1198
1214
  findOneAndDelete<const Projection extends ProjectionType<TRawDocType>>(
1199
1215
  filter: QueryFilter<TRawDocType>,
@@ -1204,7 +1220,8 @@ declare module 'mongoose' {
1204
1220
  TQueryHelpers,
1205
1221
  TLeanResultType,
1206
1222
  'findOneAndDelete',
1207
- TInstanceMethods & TVirtuals
1223
+ TInstanceMethods & TVirtuals,
1224
+ ApplyProjection<TLeanResultType, Projection>
1208
1225
  >;
1209
1226
  findOneAndDelete<ResultDoc = THydratedDocumentType>(
1210
1227
  filter: QueryFilter<TRawDocType>,
@@ -1306,7 +1323,8 @@ declare module 'mongoose' {
1306
1323
  TQueryHelpers,
1307
1324
  TLeanResultType,
1308
1325
  'findOneAndReplace',
1309
- TInstanceMethods & TVirtuals
1326
+ TInstanceMethods & TVirtuals,
1327
+ ApplyProjection<TLeanResultType, Projection>
1310
1328
  >;
1311
1329
  findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
1312
1330
  filter: QueryFilter<TRawDocType>,
@@ -1318,7 +1336,8 @@ declare module 'mongoose' {
1318
1336
  TQueryHelpers,
1319
1337
  TLeanResultType,
1320
1338
  'findOneAndReplace',
1321
- TInstanceMethods & TVirtuals
1339
+ TInstanceMethods & TVirtuals,
1340
+ ApplyProjection<TLeanResultType, Projection>
1322
1341
  >;
1323
1342
  findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
1324
1343
  filter: QueryFilter<TRawDocType>,
@@ -1330,7 +1349,8 @@ declare module 'mongoose' {
1330
1349
  TQueryHelpers,
1331
1350
  TLeanResultType,
1332
1351
  'findOneAndReplace',
1333
- TInstanceMethods & TVirtuals
1352
+ TInstanceMethods & TVirtuals,
1353
+ ApplyProjection<TLeanResultType, Projection>
1334
1354
  >;
1335
1355
  findOneAndReplace<const Projection extends ProjectionType<TRawDocType>>(
1336
1356
  filter: QueryFilter<TRawDocType>,
@@ -1342,7 +1362,8 @@ declare module 'mongoose' {
1342
1362
  TQueryHelpers,
1343
1363
  TLeanResultType,
1344
1364
  'findOneAndReplace',
1345
- TInstanceMethods & TVirtuals
1365
+ TInstanceMethods & TVirtuals,
1366
+ ApplyProjection<TLeanResultType, Projection>
1346
1367
  >;
1347
1368
  findOneAndReplace<ResultDoc = THydratedDocumentType>(
1348
1369
  filter: QueryFilter<TRawDocType>,
@@ -1476,7 +1497,8 @@ declare module 'mongoose' {
1476
1497
  TQueryHelpers,
1477
1498
  TLeanResultType,
1478
1499
  'findOneAndUpdate',
1479
- TInstanceMethods & TVirtuals
1500
+ TInstanceMethods & TVirtuals,
1501
+ ApplyProjection<TLeanResultType, Projection>
1480
1502
  >;
1481
1503
  findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
1482
1504
  filter: QueryFilter<TRawDocType>,
@@ -1488,7 +1510,8 @@ declare module 'mongoose' {
1488
1510
  TQueryHelpers,
1489
1511
  TLeanResultType,
1490
1512
  'findOneAndUpdate',
1491
- TInstanceMethods & TVirtuals
1513
+ TInstanceMethods & TVirtuals,
1514
+ ApplyProjection<TLeanResultType, Projection>
1492
1515
  >;
1493
1516
  findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
1494
1517
  filter: QueryFilter<TRawDocType>,
@@ -1500,7 +1523,8 @@ declare module 'mongoose' {
1500
1523
  TQueryHelpers,
1501
1524
  TLeanResultType,
1502
1525
  'findOneAndUpdate',
1503
- TInstanceMethods & TVirtuals
1526
+ TInstanceMethods & TVirtuals,
1527
+ ApplyProjection<TLeanResultType, Projection>
1504
1528
  >;
1505
1529
  findOneAndUpdate<const Projection extends ProjectionType<TRawDocType>>(
1506
1530
  filter: QueryFilter<TRawDocType>,
@@ -1512,7 +1536,8 @@ declare module 'mongoose' {
1512
1536
  TQueryHelpers,
1513
1537
  TLeanResultType,
1514
1538
  'findOneAndUpdate',
1515
- TInstanceMethods & TVirtuals
1539
+ TInstanceMethods & TVirtuals,
1540
+ ApplyProjection<TLeanResultType, Projection>
1516
1541
  >;
1517
1542
  findOneAndUpdate<ResultDoc = THydratedDocumentType>(
1518
1543
  filter: QueryFilter<TRawDocType>,
@@ -1543,7 +1568,7 @@ declare module 'mongoose' {
1543
1568
  update: UpdateQuery<TRawDocType>,
1544
1569
  options: QueryOptions<TRawDocType> & { lean: true }
1545
1570
  ): QueryWithHelpers<
1546
- GetLeanResultType<TRawDocType, TRawDocType, 'findOneAndUpdate'> | null,
1571
+ GetLeanResultType<TLeanResultType, TRawDocType, 'findOneAndUpdate'> | null,
1547
1572
  ResultDoc,
1548
1573
  TQueryHelpers,
1549
1574
  TLeanResultType,
@@ -1555,7 +1580,7 @@ declare module 'mongoose' {
1555
1580
  update: UpdateQuery<TRawDocType>,
1556
1581
  options: QueryOptions<TRawDocType> & { lean: true }
1557
1582
  ): QueryWithHelpers<
1558
- GetLeanResultType<TRawDocType, TRawDocType, 'findOneAndUpdate'> | null,
1583
+ GetLeanResultType<TLeanResultType, TRawDocType, 'findOneAndUpdate'> | null,
1559
1584
  THydratedDocumentType,
1560
1585
  TQueryHelpers,
1561
1586
  TLeanResultType,