mongoose 8.5.5 → 8.6.1

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/types/models.d.ts CHANGED
@@ -188,7 +188,7 @@ declare module 'mongoose' {
188
188
 
189
189
  export interface ReplaceOneModel<TSchema = AnyObject> {
190
190
  /** The filter to limit the replaced document. */
191
- filter: FilterQuery<TSchema>;
191
+ filter: RootFilterQuery<TSchema>;
192
192
  /** The document with which to replace the matched document. */
193
193
  replacement: mongodb.WithoutId<TSchema>;
194
194
  /** Specifies a collation. */
@@ -203,7 +203,7 @@ declare module 'mongoose' {
203
203
 
204
204
  export interface UpdateOneModel<TSchema = AnyObject> {
205
205
  /** The filter to limit the updated documents. */
206
- filter: FilterQuery<TSchema>;
206
+ filter: RootFilterQuery<TSchema>;
207
207
  /** A document or pipeline containing update operators. */
208
208
  update: UpdateQuery<TSchema>;
209
209
  /** A set of filters specifying to which array elements an update should apply. */
@@ -220,7 +220,7 @@ declare module 'mongoose' {
220
220
 
221
221
  export interface UpdateManyModel<TSchema = AnyObject> {
222
222
  /** The filter to limit the updated documents. */
223
- filter: FilterQuery<TSchema>;
223
+ filter: RootFilterQuery<TSchema>;
224
224
  /** A document or pipeline containing update operators. */
225
225
  update: UpdateQuery<TSchema>;
226
226
  /** A set of filters specifying to which array elements an update should apply. */
@@ -237,7 +237,7 @@ declare module 'mongoose' {
237
237
 
238
238
  export interface DeleteOneModel<TSchema = AnyObject> {
239
239
  /** The filter to limit the deleted documents. */
240
- filter: FilterQuery<TSchema>;
240
+ filter: RootFilterQuery<TSchema>;
241
241
  /** Specifies a collation. */
242
242
  collation?: mongodb.CollationOptions;
243
243
  /** The index to use. If specified, then the query system will only consider plans using the hinted index. */
@@ -246,7 +246,7 @@ declare module 'mongoose' {
246
246
 
247
247
  export interface DeleteManyModel<TSchema = AnyObject> {
248
248
  /** The filter to limit the deleted documents. */
249
- filter: FilterQuery<TSchema>;
249
+ filter: RootFilterQuery<TSchema>;
250
250
  /** Specifies a collation. */
251
251
  collation?: mongodb.CollationOptions;
252
252
  /** The index to use. If specified, then the query system will only consider plans using the hinted index. */
@@ -318,7 +318,7 @@ declare module 'mongoose' {
318
318
 
319
319
  /** Creates a `countDocuments` query: counts the number of documents that match `filter`. */
320
320
  countDocuments(
321
- filter?: FilterQuery<TRawDocType>,
321
+ filter?: RootFilterQuery<TRawDocType>,
322
322
  options?: (mongodb.CountOptions & MongooseBaseQueryOptions<TRawDocType>) | null
323
323
  ): QueryWithHelpers<
324
324
  number,
@@ -357,7 +357,7 @@ declare module 'mongoose' {
357
357
  * regardless of the `single` option.
358
358
  */
359
359
  deleteMany(
360
- filter?: FilterQuery<TRawDocType>,
360
+ filter?: RootFilterQuery<TRawDocType>,
361
361
  options?: (mongodb.DeleteOptions & MongooseBaseQueryOptions<TRawDocType>) | null
362
362
  ): QueryWithHelpers<
363
363
  mongodb.DeleteResult,
@@ -368,7 +368,7 @@ declare module 'mongoose' {
368
368
  TInstanceMethods
369
369
  >;
370
370
  deleteMany(
371
- filter: FilterQuery<TRawDocType>
371
+ filter: RootFilterQuery<TRawDocType>
372
372
  ): QueryWithHelpers<
373
373
  mongodb.DeleteResult,
374
374
  THydratedDocumentType,
@@ -384,7 +384,7 @@ declare module 'mongoose' {
384
384
  * `single` option.
385
385
  */
386
386
  deleteOne(
387
- filter?: FilterQuery<TRawDocType>,
387
+ filter?: RootFilterQuery<TRawDocType>,
388
388
  options?: (mongodb.DeleteOptions & MongooseBaseQueryOptions<TRawDocType>) | null
389
389
  ): QueryWithHelpers<
390
390
  mongodb.DeleteResult,
@@ -395,7 +395,7 @@ declare module 'mongoose' {
395
395
  TInstanceMethods
396
396
  >;
397
397
  deleteOne(
398
- filter: FilterQuery<TRawDocType>
398
+ filter: RootFilterQuery<TRawDocType>
399
399
  ): QueryWithHelpers<
400
400
  mongodb.DeleteResult,
401
401
  THydratedDocumentType,
@@ -446,7 +446,7 @@ declare module 'mongoose' {
446
446
 
447
447
  /** Finds one document. */
448
448
  findOne<ResultDoc = THydratedDocumentType>(
449
- filter: FilterQuery<TRawDocType>,
449
+ filter: RootFilterQuery<TRawDocType>,
450
450
  projection: ProjectionType<TRawDocType> | null | undefined,
451
451
  options: QueryOptions<TRawDocType> & { lean: true }
452
452
  ): QueryWithHelpers<
@@ -458,16 +458,16 @@ declare module 'mongoose' {
458
458
  TInstanceMethods
459
459
  >;
460
460
  findOne<ResultDoc = THydratedDocumentType>(
461
- filter?: FilterQuery<TRawDocType>,
461
+ filter?: RootFilterQuery<TRawDocType>,
462
462
  projection?: ProjectionType<TRawDocType> | null,
463
463
  options?: QueryOptions<TRawDocType> | null
464
464
  ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOne', TInstanceMethods>;
465
465
  findOne<ResultDoc = THydratedDocumentType>(
466
- filter?: FilterQuery<TRawDocType>,
466
+ filter?: RootFilterQuery<TRawDocType>,
467
467
  projection?: ProjectionType<TRawDocType> | null
468
468
  ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOne', TInstanceMethods>;
469
469
  findOne<ResultDoc = THydratedDocumentType>(
470
- filter?: FilterQuery<TRawDocType>
470
+ filter?: RootFilterQuery<TRawDocType>
471
471
  ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOne', TInstanceMethods>;
472
472
 
473
473
  /**
@@ -621,7 +621,8 @@ declare module 'mongoose' {
621
621
  /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
622
622
  distinct<DocKey extends string, ResultType = unknown>(
623
623
  field: DocKey,
624
- filter?: FilterQuery<TRawDocType>
624
+ filter?: RootFilterQuery<TRawDocType>,
625
+ options?: QueryOptions<TRawDocType>
625
626
  ): QueryWithHelpers<
626
627
  Array<
627
628
  DocKey extends keyof WithLevel1NestedPaths<TRawDocType>
@@ -650,7 +651,7 @@ declare module 'mongoose' {
650
651
  * the given `filter`, and `null` otherwise.
651
652
  */
652
653
  exists(
653
- filter: FilterQuery<TRawDocType>
654
+ filter: RootFilterQuery<TRawDocType>
654
655
  ): QueryWithHelpers<
655
656
  { _id: InferId<TRawDocType> } | null,
656
657
  THydratedDocumentType,
@@ -662,7 +663,7 @@ declare module 'mongoose' {
662
663
 
663
664
  /** Creates a `find` query: gets a list of documents that match `filter`. */
664
665
  find<ResultDoc = THydratedDocumentType>(
665
- filter: FilterQuery<TRawDocType>,
666
+ filter: RootFilterQuery<TRawDocType>,
666
667
  projection: ProjectionType<TRawDocType> | null | undefined,
667
668
  options: QueryOptions<TRawDocType> & { lean: true }
668
669
  ): QueryWithHelpers<
@@ -674,16 +675,16 @@ declare module 'mongoose' {
674
675
  TInstanceMethods
675
676
  >;
676
677
  find<ResultDoc = THydratedDocumentType>(
677
- filter: FilterQuery<TRawDocType>,
678
+ filter: RootFilterQuery<TRawDocType>,
678
679
  projection?: ProjectionType<TRawDocType> | null | undefined,
679
680
  options?: QueryOptions<TRawDocType> | null | undefined
680
681
  ): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>;
681
682
  find<ResultDoc = THydratedDocumentType>(
682
- filter: FilterQuery<TRawDocType>,
683
+ filter: RootFilterQuery<TRawDocType>,
683
684
  projection?: ProjectionType<TRawDocType> | null | undefined
684
685
  ): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>;
685
686
  find<ResultDoc = THydratedDocumentType>(
686
- filter: FilterQuery<TRawDocType>
687
+ filter: RootFilterQuery<TRawDocType>
687
688
  ): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>;
688
689
  find<ResultDoc = THydratedDocumentType>(
689
690
  ): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>;
@@ -711,7 +712,7 @@ declare module 'mongoose' {
711
712
 
712
713
  /** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
713
714
  findByIdAndUpdate<ResultDoc = THydratedDocumentType>(
714
- filter: FilterQuery<TRawDocType>,
715
+ filter: RootFilterQuery<TRawDocType>,
715
716
  update: UpdateQuery<TRawDocType>,
716
717
  options: QueryOptions<TRawDocType> & { includeResultMetadata: true, lean: true }
717
718
  ): QueryWithHelpers<
@@ -756,7 +757,7 @@ declare module 'mongoose' {
756
757
 
757
758
  /** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
758
759
  findOneAndDelete<ResultDoc = THydratedDocumentType>(
759
- filter: FilterQuery<TRawDocType>,
760
+ filter: RootFilterQuery<TRawDocType>,
760
761
  options: QueryOptions<TRawDocType> & { lean: true }
761
762
  ): QueryWithHelpers<
762
763
  GetLeanResultType<TRawDocType, TRawDocType, 'findOneAndDelete'> | null,
@@ -767,17 +768,17 @@ declare module 'mongoose' {
767
768
  TInstanceMethods
768
769
  >;
769
770
  findOneAndDelete<ResultDoc = THydratedDocumentType>(
770
- filter: FilterQuery<TRawDocType>,
771
+ filter: RootFilterQuery<TRawDocType>,
771
772
  options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
772
773
  ): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete', TInstanceMethods>;
773
774
  findOneAndDelete<ResultDoc = THydratedDocumentType>(
774
- filter?: FilterQuery<TRawDocType> | null,
775
+ filter?: RootFilterQuery<TRawDocType> | null,
775
776
  options?: QueryOptions<TRawDocType> | null
776
777
  ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete', TInstanceMethods>;
777
778
 
778
779
  /** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
779
780
  findOneAndReplace<ResultDoc = THydratedDocumentType>(
780
- filter: FilterQuery<TRawDocType>,
781
+ filter: RootFilterQuery<TRawDocType>,
781
782
  replacement: TRawDocType | AnyObject,
782
783
  options: QueryOptions<TRawDocType> & { lean: true }
783
784
  ): QueryWithHelpers<
@@ -789,24 +790,24 @@ declare module 'mongoose' {
789
790
  TInstanceMethods
790
791
  >;
791
792
  findOneAndReplace<ResultDoc = THydratedDocumentType>(
792
- filter: FilterQuery<TRawDocType>,
793
+ filter: RootFilterQuery<TRawDocType>,
793
794
  replacement: TRawDocType | AnyObject,
794
795
  options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
795
796
  ): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndReplace', TInstanceMethods>;
796
797
  findOneAndReplace<ResultDoc = THydratedDocumentType>(
797
- filter: FilterQuery<TRawDocType>,
798
+ filter: RootFilterQuery<TRawDocType>,
798
799
  replacement: TRawDocType | AnyObject,
799
800
  options: QueryOptions<TRawDocType> & { upsert: true } & ReturnsNewDoc
800
801
  ): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndReplace', TInstanceMethods>;
801
802
  findOneAndReplace<ResultDoc = THydratedDocumentType>(
802
- filter?: FilterQuery<TRawDocType>,
803
+ filter?: RootFilterQuery<TRawDocType>,
803
804
  replacement?: TRawDocType | AnyObject,
804
805
  options?: QueryOptions<TRawDocType> | null
805
806
  ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndReplace', TInstanceMethods>;
806
807
 
807
808
  /** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
808
809
  findOneAndUpdate<ResultDoc = THydratedDocumentType>(
809
- filter: FilterQuery<TRawDocType>,
810
+ filter: RootFilterQuery<TRawDocType>,
810
811
  update: UpdateQuery<TRawDocType>,
811
812
  options: QueryOptions<TRawDocType> & { includeResultMetadata: true, lean: true }
812
813
  ): QueryWithHelpers<
@@ -818,7 +819,7 @@ declare module 'mongoose' {
818
819
  TInstanceMethods
819
820
  >;
820
821
  findOneAndUpdate<ResultDoc = THydratedDocumentType>(
821
- filter: FilterQuery<TRawDocType>,
822
+ filter: RootFilterQuery<TRawDocType>,
822
823
  update: UpdateQuery<TRawDocType>,
823
824
  options: QueryOptions<TRawDocType> & { lean: true }
824
825
  ): QueryWithHelpers<
@@ -830,24 +831,24 @@ declare module 'mongoose' {
830
831
  TInstanceMethods
831
832
  >;
832
833
  findOneAndUpdate<ResultDoc = THydratedDocumentType>(
833
- filter: FilterQuery<TRawDocType>,
834
+ filter: RootFilterQuery<TRawDocType>,
834
835
  update: UpdateQuery<TRawDocType>,
835
836
  options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
836
837
  ): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate', TInstanceMethods>;
837
838
  findOneAndUpdate<ResultDoc = THydratedDocumentType>(
838
- filter: FilterQuery<TRawDocType>,
839
+ filter: RootFilterQuery<TRawDocType>,
839
840
  update: UpdateQuery<TRawDocType>,
840
841
  options: QueryOptions<TRawDocType> & { upsert: true } & ReturnsNewDoc
841
842
  ): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate', TInstanceMethods>;
842
843
  findOneAndUpdate<ResultDoc = THydratedDocumentType>(
843
- filter?: FilterQuery<TRawDocType>,
844
+ filter?: RootFilterQuery<TRawDocType>,
844
845
  update?: UpdateQuery<TRawDocType>,
845
846
  options?: QueryOptions<TRawDocType> | null
846
847
  ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate', TInstanceMethods>;
847
848
 
848
849
  /** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */
849
850
  replaceOne<ResultDoc = THydratedDocumentType>(
850
- filter?: FilterQuery<TRawDocType>,
851
+ filter?: RootFilterQuery<TRawDocType>,
851
852
  replacement?: TRawDocType | AnyObject,
852
853
  options?: (mongodb.ReplaceOptions & MongooseQueryOptions<TRawDocType>) | null
853
854
  ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TRawDocType, 'replaceOne', TInstanceMethods>;
@@ -860,14 +861,14 @@ declare module 'mongoose' {
860
861
 
861
862
  /** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
862
863
  updateMany<ResultDoc = THydratedDocumentType>(
863
- filter?: FilterQuery<TRawDocType>,
864
+ filter?: RootFilterQuery<TRawDocType>,
864
865
  update?: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
865
866
  options?: (mongodb.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null
866
867
  ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TRawDocType, 'updateMany', TInstanceMethods>;
867
868
 
868
869
  /** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */
869
870
  updateOne<ResultDoc = THydratedDocumentType>(
870
- filter?: FilterQuery<TRawDocType>,
871
+ filter?: RootFilterQuery<TRawDocType>,
871
872
  update?: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
872
873
  options?: (mongodb.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null
873
874
  ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TRawDocType, 'updateOne', TInstanceMethods>;
package/types/query.d.ts CHANGED
@@ -10,9 +10,11 @@ declare module 'mongoose' {
10
10
  * { age: { $gte: 30 } }
11
11
  * ```
12
12
  */
13
- type FilterQuery<T> = {
13
+ type RootFilterQuery<T> = FilterQuery<T> | Query<any, any> | Types.ObjectId;
14
+
15
+ type FilterQuery<T> ={
14
16
  [P in keyof T]?: Condition<T[P]>;
15
- } & RootQuerySelector<T>;
17
+ } & RootQuerySelector<T> & { _id?: Condition<string>; };
16
18
 
17
19
  type MongooseBaseQueryOptionKeys =
18
20
  | 'context'
@@ -114,9 +116,11 @@ declare module 'mongoose' {
114
116
  $where?: string | Function;
115
117
  /** @see https://www.mongodb.com/docs/manual/reference/operator/query/comment/#op._S_comment */
116
118
  $comment?: string;
119
+ $expr?: Record<string, any>;
117
120
  // we could not find a proper TypeScript generic to support nested queries e.g. 'user.friends.name'
118
- // this will mark all unrecognized properties as any (including nested queries)
119
- [key: string]: any;
121
+ // this will mark all unrecognized properties as any (including nested queries) only if
122
+ // they include a "." (to avoid generically allowing any unexpected keys)
123
+ [nestedSelector: `${string}.${string}`]: any;
120
124
  };
121
125
 
122
126
  interface QueryTimestampsConfig {
@@ -224,7 +228,7 @@ declare module 'mongoose' {
224
228
  : MergeType<ResultType, Paths>
225
229
  : MergeType<ResultType, Paths>;
226
230
 
227
- class Query<ResultType, DocType, THelpers = {}, RawDocType = DocType, QueryOp = 'find', TInstanceMethods = Record<string, never>> implements SessionOperation {
231
+ class Query<ResultType, DocType, THelpers = {}, RawDocType = unknown, QueryOp = 'find', TInstanceMethods = Record<string, never>> implements SessionOperation {
228
232
  _mongooseOptions: MongooseQueryOptions<DocType>;
229
233
 
230
234
  /**
@@ -303,7 +307,7 @@ declare module 'mongoose' {
303
307
 
304
308
  /** Specifies this query as a `countDocuments` query. */
305
309
  countDocuments(
306
- criteria?: FilterQuery<RawDocType>,
310
+ criteria?: RootFilterQuery<RawDocType>,
307
311
  options?: QueryOptions<DocType>
308
312
  ): QueryWithHelpers<number, DocType, THelpers, RawDocType, 'countDocuments', TInstanceMethods>;
309
313
 
@@ -319,10 +323,10 @@ declare module 'mongoose' {
319
323
  * collection, regardless of the value of `single`.
320
324
  */
321
325
  deleteMany(
322
- filter?: FilterQuery<RawDocType>,
326
+ filter?: RootFilterQuery<RawDocType>,
323
327
  options?: QueryOptions<DocType>
324
328
  ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany', TInstanceMethods>;
325
- deleteMany(filter: FilterQuery<RawDocType>): QueryWithHelpers<
329
+ deleteMany(filter: RootFilterQuery<RawDocType>): QueryWithHelpers<
326
330
  any,
327
331
  DocType,
328
332
  THelpers,
@@ -338,10 +342,10 @@ declare module 'mongoose' {
338
342
  * option.
339
343
  */
340
344
  deleteOne(
341
- filter?: FilterQuery<RawDocType>,
345
+ filter?: RootFilterQuery<RawDocType>,
342
346
  options?: QueryOptions<DocType>
343
347
  ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne', TInstanceMethods>;
344
- deleteOne(filter: FilterQuery<RawDocType>): QueryWithHelpers<
348
+ deleteOne(filter: RootFilterQuery<RawDocType>): QueryWithHelpers<
345
349
  any,
346
350
  DocType,
347
351
  THelpers,
@@ -354,7 +358,8 @@ declare module 'mongoose' {
354
358
  /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
355
359
  distinct<DocKey extends string, ResultType = unknown>(
356
360
  field: DocKey,
357
- filter?: FilterQuery<RawDocType>
361
+ filter?: RootFilterQuery<RawDocType>,
362
+ options?: QueryOptions<DocType>
358
363
  ): QueryWithHelpers<
359
364
  Array<
360
365
  DocKey extends keyof WithLevel1NestedPaths<DocType>
@@ -406,52 +411,52 @@ declare module 'mongoose' {
406
411
 
407
412
  /** Creates a `find` query: gets a list of documents that match `filter`. */
408
413
  find(
409
- filter: FilterQuery<RawDocType>,
414
+ filter: RootFilterQuery<RawDocType>,
410
415
  projection?: ProjectionType<RawDocType> | null,
411
416
  options?: QueryOptions<DocType> | null
412
417
  ): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TInstanceMethods>;
413
418
  find(
414
- filter: FilterQuery<RawDocType>,
419
+ filter: RootFilterQuery<RawDocType>,
415
420
  projection?: ProjectionType<RawDocType> | null
416
421
  ): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TInstanceMethods>;
417
422
  find(
418
- filter: FilterQuery<RawDocType>
423
+ filter: RootFilterQuery<RawDocType>
419
424
  ): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TInstanceMethods>;
420
425
  find(): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TInstanceMethods>;
421
426
 
422
427
  /** Declares the query a findOne operation. When executed, returns the first found document. */
423
428
  findOne(
424
- filter?: FilterQuery<RawDocType>,
429
+ filter?: RootFilterQuery<RawDocType>,
425
430
  projection?: ProjectionType<RawDocType> | null,
426
431
  options?: QueryOptions<DocType> | null
427
432
  ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
428
433
  findOne(
429
- filter?: FilterQuery<RawDocType>,
434
+ filter?: RootFilterQuery<RawDocType>,
430
435
  projection?: ProjectionType<RawDocType> | null
431
436
  ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
432
437
  findOne(
433
- filter?: FilterQuery<RawDocType>
438
+ filter?: RootFilterQuery<RawDocType>
434
439
  ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
435
440
 
436
441
  /** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
437
442
  findOneAndDelete(
438
- filter?: FilterQuery<RawDocType>,
443
+ filter?: RootFilterQuery<RawDocType>,
439
444
  options?: QueryOptions<DocType> | null
440
445
  ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete'>;
441
446
 
442
447
  /** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
443
448
  findOneAndUpdate(
444
- filter: FilterQuery<RawDocType>,
449
+ filter: RootFilterQuery<RawDocType>,
445
450
  update: UpdateQuery<RawDocType>,
446
451
  options: QueryOptions<DocType> & { includeResultMetadata: true }
447
452
  ): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>;
448
453
  findOneAndUpdate(
449
- filter: FilterQuery<RawDocType>,
454
+ filter: RootFilterQuery<RawDocType>,
450
455
  update: UpdateQuery<RawDocType>,
451
456
  options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc
452
457
  ): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>;
453
458
  findOneAndUpdate(
454
- filter?: FilterQuery<RawDocType>,
459
+ filter?: RootFilterQuery<RawDocType>,
455
460
  update?: UpdateQuery<RawDocType>,
456
461
  options?: QueryOptions<DocType> | null
457
462
  ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>;
@@ -548,9 +553,19 @@ declare module 'mongoose' {
548
553
  j(val: boolean | null): this;
549
554
 
550
555
  /** Sets the lean option. */
551
- lean<
552
- LeanResultType = GetLeanResultType<RawDocType, ResultType, QueryOp>
553
- >(
556
+ lean(
557
+ val?: boolean | any
558
+ ): QueryWithHelpers<
559
+ ResultType extends null
560
+ ? GetLeanResultType<RawDocType, ResultType, QueryOp> | null
561
+ : GetLeanResultType<RawDocType, ResultType, QueryOp>,
562
+ DocType,
563
+ THelpers,
564
+ RawDocType,
565
+ QueryOp,
566
+ TInstanceMethods
567
+ >;
568
+ lean<LeanResultType>(
554
569
  val?: boolean | any
555
570
  ): QueryWithHelpers<
556
571
  ResultType extends null
@@ -592,7 +607,7 @@ declare module 'mongoose' {
592
607
  maxTimeMS(ms: number): this;
593
608
 
594
609
  /** Merges another Query or conditions object into this one. */
595
- merge(source: Query<any, any> | FilterQuery<RawDocType>): this;
610
+ merge(source: RootFilterQuery<RawDocType>): this;
596
611
 
597
612
  /** Specifies a `$mod` condition, filters documents for documents whose `path` property is a number that is equal to `remainder` modulo `divisor`. */
598
613
  mod<K = string>(path: K, val: number): this;
@@ -711,7 +726,7 @@ declare module 'mongoose' {
711
726
  * not accept any [atomic](https://www.mongodb.com/docs/manual/tutorial/model-data-for-atomic-operations/#pattern) operators (`$set`, etc.)
712
727
  */
713
728
  replaceOne(
714
- filter?: FilterQuery<RawDocType>,
729
+ filter?: RootFilterQuery<RawDocType>,
715
730
  replacement?: DocType | AnyObject,
716
731
  options?: QueryOptions<DocType> | null
717
732
  ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'replaceOne', TInstanceMethods>;
@@ -819,7 +834,7 @@ declare module 'mongoose' {
819
834
  * the `multi` option.
820
835
  */
821
836
  updateMany(
822
- filter?: FilterQuery<RawDocType>,
837
+ filter?: RootFilterQuery<RawDocType>,
823
838
  update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
824
839
  options?: QueryOptions<DocType> | null
825
840
  ): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany', TInstanceMethods>;
@@ -829,7 +844,7 @@ declare module 'mongoose' {
829
844
  * `update()`, except it does not support the `multi` or `overwrite` options.
830
845
  */
831
846
  updateOne(
832
- filter?: FilterQuery<RawDocType>,
847
+ filter?: RootFilterQuery<RawDocType>,
833
848
  update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
834
849
  options?: QueryOptions<DocType> | null
835
850
  ): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne', TInstanceMethods>;