mongoose 8.9.2 → 8.9.4

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/query.d.ts CHANGED
@@ -53,8 +53,8 @@ declare module 'mongoose' {
53
53
  THelpers = {},
54
54
  RawDocType = DocType,
55
55
  QueryOp = 'find',
56
- TInstanceMethods = Record<string, never>
57
- > = Query<ResultType, DocType, THelpers, RawDocType, QueryOp, TInstanceMethods> & THelpers;
56
+ TDocOverrides = Record<string, never>
57
+ > = Query<ResultType, DocType, THelpers, RawDocType, QueryOp, TDocOverrides> & THelpers;
58
58
 
59
59
  type QuerySelector<T> = {
60
60
  // Comparison
@@ -223,22 +223,22 @@ declare module 'mongoose' {
223
223
  type QueryOpThatReturnsDocument = 'find' | 'findOne' | 'findOneAndUpdate' | 'findOneAndReplace' | 'findOneAndDelete';
224
224
 
225
225
  type GetLeanResultType<RawDocType, ResultType, QueryOp> = QueryOp extends QueryOpThatReturnsDocument
226
- ? (ResultType extends any[] ? Default__v<Require_id<BufferToBinary<FlattenMaps<RawDocType>>>>[] : Default__v<Require_id<BufferToBinary<FlattenMaps<RawDocType>>>>)
226
+ ? (ResultType extends any[] ? Default__v<Require_id<FlattenMaps<BufferToBinary<RawDocType>>>>[] : Default__v<Require_id<FlattenMaps<BufferToBinary<RawDocType>>>>)
227
227
  : ResultType;
228
228
 
229
- type MergePopulatePaths<RawDocType, ResultType, QueryOp, Paths, TQueryHelpers, TInstanceMethods = Record<string, never>> = QueryOp extends QueryOpThatReturnsDocument
229
+ type MergePopulatePaths<RawDocType, ResultType, QueryOp, Paths, TQueryHelpers, TDocOverrides = Record<string, never>> = QueryOp extends QueryOpThatReturnsDocument
230
230
  ? ResultType extends null
231
231
  ? ResultType
232
232
  : ResultType extends (infer U)[]
233
233
  ? U extends Document
234
- ? HydratedDocument<MergeType<RawDocType, Paths>, TInstanceMethods, TQueryHelpers>[]
234
+ ? HydratedDocument<MergeType<RawDocType, Paths>, TDocOverrides, TQueryHelpers>[]
235
235
  : (MergeType<U, Paths>)[]
236
236
  : ResultType extends Document
237
- ? HydratedDocument<MergeType<RawDocType, Paths>, TInstanceMethods, TQueryHelpers>
237
+ ? HydratedDocument<MergeType<RawDocType, Paths>, TDocOverrides, TQueryHelpers>
238
238
  : MergeType<ResultType, Paths>
239
239
  : MergeType<ResultType, Paths>;
240
240
 
241
- class Query<ResultType, DocType, THelpers = {}, RawDocType = unknown, QueryOp = 'find', TInstanceMethods = Record<string, never>> implements SessionOperation {
241
+ class Query<ResultType, DocType, THelpers = {}, RawDocType = unknown, QueryOp = 'find', TDocOverrides = Record<string, never>> implements SessionOperation {
242
242
  _mongooseOptions: MongooseQueryOptions<DocType>;
243
243
 
244
244
  /**
@@ -257,7 +257,7 @@ declare module 'mongoose' {
257
257
  THelpers,
258
258
  RawDocType,
259
259
  QueryOp,
260
- TInstanceMethods
260
+ TDocOverrides
261
261
  >;
262
262
 
263
263
  /** Specifies an `$all` query condition. When called with one argument, the most recent path passed to `where()` is used. */
@@ -319,7 +319,7 @@ declare module 'mongoose' {
319
319
  countDocuments(
320
320
  criteria?: RootFilterQuery<RawDocType>,
321
321
  options?: QueryOptions<DocType>
322
- ): QueryWithHelpers<number, DocType, THelpers, RawDocType, 'countDocuments', TInstanceMethods>;
322
+ ): QueryWithHelpers<number, DocType, THelpers, RawDocType, 'countDocuments', TDocOverrides>;
323
323
 
324
324
  /**
325
325
  * Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html).
@@ -335,16 +335,16 @@ declare module 'mongoose' {
335
335
  deleteMany(
336
336
  filter?: RootFilterQuery<RawDocType>,
337
337
  options?: QueryOptions<DocType>
338
- ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany', TInstanceMethods>;
338
+ ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany', TDocOverrides>;
339
339
  deleteMany(filter: RootFilterQuery<RawDocType>): QueryWithHelpers<
340
340
  any,
341
341
  DocType,
342
342
  THelpers,
343
343
  RawDocType,
344
344
  'deleteMany',
345
- TInstanceMethods
345
+ TDocOverrides
346
346
  >;
347
- deleteMany(): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany', TInstanceMethods>;
347
+ deleteMany(): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteMany', TDocOverrides>;
348
348
 
349
349
  /**
350
350
  * Declare and/or execute this query as a `deleteOne()` operation. Works like
@@ -354,16 +354,16 @@ declare module 'mongoose' {
354
354
  deleteOne(
355
355
  filter?: RootFilterQuery<RawDocType>,
356
356
  options?: QueryOptions<DocType>
357
- ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne', TInstanceMethods>;
357
+ ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne', TDocOverrides>;
358
358
  deleteOne(filter: RootFilterQuery<RawDocType>): QueryWithHelpers<
359
359
  any,
360
360
  DocType,
361
361
  THelpers,
362
362
  RawDocType,
363
363
  'deleteOne',
364
- TInstanceMethods
364
+ TDocOverrides
365
365
  >;
366
- deleteOne(): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne', TInstanceMethods>;
366
+ deleteOne(): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'deleteOne', TDocOverrides>;
367
367
 
368
368
  /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
369
369
  distinct<DocKey extends string, ResultType = unknown>(
@@ -380,7 +380,7 @@ declare module 'mongoose' {
380
380
  THelpers,
381
381
  RawDocType,
382
382
  'distinct',
383
- TInstanceMethods
383
+ TDocOverrides
384
384
  >;
385
385
 
386
386
  /** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */
@@ -404,7 +404,7 @@ declare module 'mongoose' {
404
404
  THelpers,
405
405
  RawDocType,
406
406
  'estimatedDocumentCount',
407
- TInstanceMethods
407
+ TDocOverrides
408
408
  >;
409
409
 
410
410
  /** Specifies a `$exists` query condition. When called with one argument, the most recent path passed to `where()` is used. */
@@ -424,29 +424,29 @@ declare module 'mongoose' {
424
424
  filter: RootFilterQuery<RawDocType>,
425
425
  projection?: ProjectionType<RawDocType> | null,
426
426
  options?: QueryOptions<DocType> | null
427
- ): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TInstanceMethods>;
427
+ ): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
428
428
  find(
429
429
  filter: RootFilterQuery<RawDocType>,
430
430
  projection?: ProjectionType<RawDocType> | null
431
- ): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TInstanceMethods>;
431
+ ): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
432
432
  find(
433
433
  filter: RootFilterQuery<RawDocType>
434
- ): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TInstanceMethods>;
435
- find(): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TInstanceMethods>;
434
+ ): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
435
+ find(): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
436
436
 
437
437
  /** Declares the query a findOne operation. When executed, returns the first found document. */
438
438
  findOne(
439
439
  filter?: RootFilterQuery<RawDocType>,
440
440
  projection?: ProjectionType<RawDocType> | null,
441
441
  options?: QueryOptions<DocType> | null
442
- ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
442
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
443
443
  findOne(
444
444
  filter?: RootFilterQuery<RawDocType>,
445
445
  projection?: ProjectionType<RawDocType> | null
446
- ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
446
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
447
447
  findOne(
448
448
  filter?: RootFilterQuery<RawDocType>
449
- ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
449
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
450
450
 
451
451
  /** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
452
452
  findOneAndDelete(
@@ -459,62 +459,62 @@ declare module 'mongoose' {
459
459
  filter: RootFilterQuery<RawDocType>,
460
460
  update: UpdateQuery<RawDocType>,
461
461
  options: QueryOptions<DocType> & { includeResultMetadata: true }
462
- ): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>;
462
+ ): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
463
463
  findOneAndUpdate(
464
464
  filter: RootFilterQuery<RawDocType>,
465
465
  update: UpdateQuery<RawDocType>,
466
466
  options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc
467
- ): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>;
467
+ ): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
468
468
  findOneAndUpdate(
469
469
  filter?: RootFilterQuery<RawDocType>,
470
470
  update?: UpdateQuery<RawDocType>,
471
471
  options?: QueryOptions<DocType> | null
472
- ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>;
472
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
473
473
 
474
474
  /** Declares the query a findById operation. When executed, returns the document with the given `_id`. */
475
475
  findById(
476
476
  id: mongodb.ObjectId | any,
477
477
  projection?: ProjectionType<RawDocType> | null,
478
478
  options?: QueryOptions<DocType> | null
479
- ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
479
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
480
480
  findById(
481
481
  id: mongodb.ObjectId | any,
482
482
  projection?: ProjectionType<RawDocType> | null
483
- ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
483
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
484
484
  findById(
485
485
  id: mongodb.ObjectId | any
486
- ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TInstanceMethods>;
486
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
487
487
 
488
488
  /** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
489
489
  findByIdAndDelete(
490
490
  id: mongodb.ObjectId | any,
491
491
  options: QueryOptions<DocType> & { includeResultMetadata: true }
492
- ): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndDelete', TInstanceMethods>;
492
+ ): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndDelete', TDocOverrides>;
493
493
  findByIdAndDelete(
494
494
  id?: mongodb.ObjectId | any,
495
495
  options?: QueryOptions<DocType> | null
496
- ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete', TInstanceMethods>;
496
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndDelete', TDocOverrides>;
497
497
 
498
498
  /** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
499
499
  findByIdAndUpdate(
500
500
  id: mongodb.ObjectId | any,
501
501
  update: UpdateQuery<RawDocType>,
502
502
  options: QueryOptions<DocType> & { includeResultMetadata: true }
503
- ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>;
503
+ ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
504
504
  findByIdAndUpdate(
505
505
  id: mongodb.ObjectId | any,
506
506
  update: UpdateQuery<RawDocType>,
507
507
  options: QueryOptions<DocType> & { upsert: true } & ReturnsNewDoc
508
- ): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>;
508
+ ): QueryWithHelpers<DocType, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
509
509
  findByIdAndUpdate(
510
510
  id?: mongodb.ObjectId | any,
511
511
  update?: UpdateQuery<RawDocType>,
512
512
  options?: QueryOptions<DocType> | null
513
- ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>;
513
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
514
514
  findByIdAndUpdate(
515
515
  id: mongodb.ObjectId | any,
516
516
  update: UpdateQuery<RawDocType>
517
- ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>;
517
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>;
518
518
 
519
519
  /** Specifies a `$geometry` condition */
520
520
  geometry(object: { type: string, coordinates: any[] }): this;
@@ -573,7 +573,7 @@ declare module 'mongoose' {
573
573
  THelpers,
574
574
  RawDocType,
575
575
  QueryOp,
576
- TInstanceMethods
576
+ TDocOverrides
577
577
  >;
578
578
  lean<LeanResultType>(
579
579
  val?: boolean | any
@@ -585,7 +585,7 @@ declare module 'mongoose' {
585
585
  THelpers,
586
586
  RawDocType,
587
587
  QueryOp,
588
- TInstanceMethods
588
+ TDocOverrides
589
589
  >;
590
590
 
591
591
  /** Specifies the maximum number of documents the query will return. */
@@ -603,7 +603,7 @@ declare module 'mongoose' {
603
603
  * Runs a function `fn` and treats the return value of `fn` as the new value
604
604
  * for the query to resolve to.
605
605
  */
606
- transform<MappedType>(fn: (doc: ResultType) => MappedType): QueryWithHelpers<MappedType, DocType, THelpers, RawDocType, QueryOp, TInstanceMethods>;
606
+ transform<MappedType>(fn: (doc: ResultType) => MappedType): QueryWithHelpers<MappedType, DocType, THelpers, RawDocType, QueryOp, TDocOverrides>;
607
607
 
608
608
  /** Specifies an `$maxDistance` query condition. When called with one argument, the most recent path passed to `where()` is used. */
609
609
  maxDistance(path: string, val: number): this;
@@ -655,7 +655,7 @@ declare module 'mongoose' {
655
655
  * This is handy for integrating with async/await, because `orFail()` saves you
656
656
  * an extra `if` statement to check if no document was found.
657
657
  */
658
- orFail(err?: NativeError | (() => NativeError)): QueryWithHelpers<NonNullable<ResultType>, DocType, THelpers, RawDocType, QueryOp, TInstanceMethods>;
658
+ orFail(err?: NativeError | (() => NativeError)): QueryWithHelpers<NonNullable<ResultType>, DocType, THelpers, RawDocType, QueryOp, TDocOverrides>;
659
659
 
660
660
  /** Specifies a `$polygon` condition */
661
661
  polygon(path: string, ...coordinatePairs: number[][]): this;
@@ -673,7 +673,7 @@ declare module 'mongoose' {
673
673
  THelpers,
674
674
  RawDocType,
675
675
  QueryOp,
676
- TInstanceMethods
676
+ TDocOverrides
677
677
  >;
678
678
  populate(
679
679
  options: PopulateOptions | (PopulateOptions | string)[]
@@ -683,7 +683,7 @@ declare module 'mongoose' {
683
683
  THelpers,
684
684
  RawDocType,
685
685
  QueryOp,
686
- TInstanceMethods
686
+ TDocOverrides
687
687
  >;
688
688
  populate<Paths>(
689
689
  path: string | string[],
@@ -691,22 +691,22 @@ declare module 'mongoose' {
691
691
  model?: string | Model<any, THelpers>,
692
692
  match?: any
693
693
  ): QueryWithHelpers<
694
- MergePopulatePaths<RawDocType, ResultType, QueryOp, Paths, THelpers, TInstanceMethods>,
694
+ MergePopulatePaths<RawDocType, ResultType, QueryOp, Paths, THelpers, TDocOverrides>,
695
695
  DocType,
696
696
  THelpers,
697
697
  UnpackedIntersection<RawDocType, Paths>,
698
698
  QueryOp,
699
- TInstanceMethods
699
+ TDocOverrides
700
700
  >;
701
701
  populate<Paths>(
702
702
  options: PopulateOptions | (PopulateOptions | string)[]
703
703
  ): QueryWithHelpers<
704
- MergePopulatePaths<RawDocType, ResultType, QueryOp, Paths, THelpers, TInstanceMethods>,
704
+ MergePopulatePaths<RawDocType, ResultType, QueryOp, Paths, THelpers, TDocOverrides>,
705
705
  DocType,
706
706
  THelpers,
707
707
  UnpackedIntersection<RawDocType, Paths>,
708
708
  QueryOp,
709
- TInstanceMethods
709
+ TDocOverrides
710
710
  >;
711
711
 
712
712
  /** Add pre middleware to this query instance. Doesn't affect other queries. */
@@ -739,7 +739,7 @@ declare module 'mongoose' {
739
739
  filter?: RootFilterQuery<RawDocType>,
740
740
  replacement?: DocType | AnyObject,
741
741
  options?: QueryOptions<DocType> | null
742
- ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'replaceOne', TInstanceMethods>;
742
+ ): QueryWithHelpers<any, DocType, THelpers, RawDocType, 'replaceOne', TDocOverrides>;
743
743
 
744
744
  /**
745
745
  * Sets this query's `sanitizeProjection` option. With `sanitizeProjection()`, you can pass potentially untrusted user data to `.select()`.
@@ -777,7 +777,7 @@ declare module 'mongoose' {
777
777
  RawDocTypeOverride
778
778
  >,
779
779
  QueryOp,
780
- TInstanceMethods
780
+ TDocOverrides
781
781
  >;
782
782
 
783
783
  /** Determines if field selection has been made. */
@@ -853,7 +853,7 @@ declare module 'mongoose' {
853
853
  filter?: RootFilterQuery<RawDocType>,
854
854
  update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
855
855
  options?: QueryOptions<DocType> | null
856
- ): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany', TInstanceMethods>;
856
+ ): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany', TDocOverrides>;
857
857
 
858
858
  /**
859
859
  * Declare and/or execute this query as an updateOne() operation. Same as
@@ -863,7 +863,7 @@ declare module 'mongoose' {
863
863
  filter?: RootFilterQuery<RawDocType>,
864
864
  update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
865
865
  options?: QueryOptions<DocType> | null
866
- ): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne', TInstanceMethods>;
866
+ ): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne', TDocOverrides>;
867
867
 
868
868
  /**
869
869
  * Sets the specified number of `mongod` servers, or tag set of `mongod` servers,