mongoose 6.1.9 → 6.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/.eslintrc.json +154 -0
  2. package/CHANGELOG.md +59 -0
  3. package/dist/browser.umd.js +233 -222
  4. package/index.js +5 -1
  5. package/lib/aggregate.js +23 -28
  6. package/lib/browserDocument.js +1 -1
  7. package/lib/cast/number.js +2 -3
  8. package/lib/cast.js +9 -7
  9. package/lib/connection.js +76 -24
  10. package/lib/cursor/AggregationCursor.js +12 -7
  11. package/lib/cursor/QueryCursor.js +11 -6
  12. package/lib/document.js +107 -107
  13. package/lib/drivers/node-mongodb-native/collection.js +12 -4
  14. package/lib/drivers/node-mongodb-native/connection.js +11 -0
  15. package/lib/error/cast.js +3 -2
  16. package/lib/error/index.js +11 -0
  17. package/lib/error/syncIndexes.js +30 -0
  18. package/lib/helpers/clone.js +51 -29
  19. package/lib/helpers/common.js +2 -2
  20. package/lib/helpers/cursor/eachAsync.js +18 -15
  21. package/lib/helpers/document/compile.js +7 -4
  22. package/lib/helpers/getFunctionName.js +6 -4
  23. package/lib/helpers/isMongooseObject.js +9 -8
  24. package/lib/helpers/isObject.js +4 -4
  25. package/lib/helpers/model/discriminator.js +2 -1
  26. package/lib/helpers/path/parentPaths.js +10 -5
  27. package/lib/helpers/populate/assignRawDocsToIdStructure.js +4 -2
  28. package/lib/helpers/populate/assignVals.js +8 -4
  29. package/lib/helpers/populate/getModelsMapForPopulate.js +4 -4
  30. package/lib/helpers/populate/markArraySubdocsPopulated.js +3 -1
  31. package/lib/helpers/populate/modelNamesFromRefPath.js +4 -3
  32. package/lib/helpers/printJestWarning.js +2 -2
  33. package/lib/helpers/projection/applyProjection.js +77 -0
  34. package/lib/helpers/projection/hasIncludedChildren.js +36 -0
  35. package/lib/helpers/projection/isExclusive.js +5 -2
  36. package/lib/helpers/projection/isInclusive.js +5 -1
  37. package/lib/helpers/query/cast$expr.js +279 -0
  38. package/lib/helpers/query/castUpdate.js +6 -2
  39. package/lib/helpers/query/isOperator.js +5 -2
  40. package/lib/helpers/schema/applyPlugins.js +11 -0
  41. package/lib/helpers/schema/getPath.js +4 -2
  42. package/lib/helpers/timestamps/setupTimestamps.js +3 -8
  43. package/lib/index.js +28 -26
  44. package/lib/internal.js +1 -1
  45. package/lib/model.js +161 -122
  46. package/lib/options/SchemaTypeOptions.js +1 -1
  47. package/lib/plugins/trackTransaction.js +5 -4
  48. package/lib/query.js +159 -146
  49. package/lib/queryhelpers.js +10 -10
  50. package/lib/schema/SubdocumentPath.js +4 -3
  51. package/lib/schema/array.js +30 -21
  52. package/lib/schema/buffer.js +1 -1
  53. package/lib/schema/date.js +1 -1
  54. package/lib/schema/decimal128.js +1 -1
  55. package/lib/schema/documentarray.js +9 -11
  56. package/lib/schema/number.js +1 -1
  57. package/lib/schema/objectid.js +2 -2
  58. package/lib/schema/string.js +4 -4
  59. package/lib/schema.js +9 -8
  60. package/lib/schematype.js +77 -30
  61. package/lib/types/ArraySubdocument.js +2 -1
  62. package/lib/types/DocumentArray/index.js +10 -27
  63. package/lib/types/DocumentArray/isMongooseDocumentArray.js +5 -0
  64. package/lib/types/DocumentArray/methods/index.js +15 -3
  65. package/lib/types/array/index.js +22 -21
  66. package/lib/types/array/isMongooseArray.js +5 -0
  67. package/lib/types/array/methods/index.js +22 -23
  68. package/lib/types/buffer.js +3 -3
  69. package/lib/types/map.js +2 -3
  70. package/lib/utils.js +10 -7
  71. package/package.json +19 -151
  72. package/tools/repl.js +1 -1
  73. package/tsconfig.json +8 -0
  74. package/types/PipelineStage.d.ts +272 -0
  75. package/{index.d.ts → types/index.d.ts} +156 -357
  76. package/lib/types/array/ArrayWrapper.js +0 -981
@@ -1,8 +1,11 @@
1
+ /// <reference path="./PipelineStage.d.ts" />
2
+
3
+ import events = require('events');
4
+ import mongodb = require('mongodb');
5
+ import mongoose = require('mongoose');
6
+ import stream = require('stream');
7
+
1
8
  declare module 'mongoose' {
2
- import events = require('events');
3
- import mongodb = require('mongodb');
4
- import mongoose = require('mongoose');
5
- import stream = require('stream');
6
9
 
7
10
  export enum ConnectionStates {
8
11
  disconnected = 0,
@@ -74,8 +77,8 @@ declare module 'mongoose' {
74
77
  * the model's schema except the `_id` index, and build any indexes that
75
78
  * are in your schema but not in MongoDB.
76
79
  */
77
- export function syncIndexes(options?: Record<string, unknown>): Promise<Array<string>>;
78
- export function syncIndexes(options: Record<string, unknown> | null, callback: Callback<Array<string>>): void;
80
+ export function syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
81
+ export function syncIndexes(options: SyncIndexesOptions | null, callback: Callback<ConnectionSyncIndexesResult>): void;
79
82
 
80
83
  /* Tells `sanitizeFilter()` to skip the given object when filtering out potential query selector injection attacks.
81
84
  * Use this method when you have a known query selector that you want to use. */
@@ -114,13 +117,14 @@ declare module 'mongoose' {
114
117
  /** Gets mongoose options */
115
118
  export function get<K extends keyof MongooseOptions>(key: K): MongooseOptions[K];
116
119
 
117
- /*! ignore */
120
+ /* ! ignore */
118
121
  type CompileModelOptions = { overwriteModels?: boolean, connection?: Connection };
119
122
 
120
123
  /**
121
124
  * Returns true if Mongoose can cast the given value to an ObjectId, or
122
125
  * false otherwise.
123
126
  */
127
+ export function isValidObjectId(v: Types.ObjectId): true;
124
128
  export function isValidObjectId(v: any): boolean;
125
129
 
126
130
  export function model<T>(name: string, schema?: Schema<T, any, any> | Schema<T & Document, any, any>, collection?: string, options?: CompileModelOptions): Model<T>;
@@ -165,6 +169,7 @@ declare module 'mongoose' {
165
169
  export const version: string;
166
170
 
167
171
  export type CastError = Error.CastError;
172
+ export type SyncIndexesError = Error.SyncIndexesError;
168
173
 
169
174
  type Mongoose = typeof mongoose;
170
175
 
@@ -260,6 +265,9 @@ declare module 'mongoose' {
260
265
  /** true by default, may be `false`, `true`, or `'throw'`. Sets the default strict mode for schemas. */
261
266
  strict?: boolean | 'throw';
262
267
 
268
+ /** true by default. set to `false` to allow populating paths that aren't in the schema */
269
+ strictPopulate?: boolean;
270
+
263
271
  /**
264
272
  * false by default, may be `false`, `true`, or `'throw'`. Sets the default
265
273
  * [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
@@ -304,7 +312,7 @@ declare module 'mongoose' {
304
312
  close(force?: boolean): Promise<void>;
305
313
 
306
314
  /** Retrieves a collection, creating it if not cached. */
307
- collection(name: string, options?: mongodb.CreateCollectionOptions): Collection;
315
+ collection<T = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Collection<T>;
308
316
 
309
317
  /** A hash of the collections associated with this connection */
310
318
  collections: { [index: string]: Collection };
@@ -320,9 +328,9 @@ declare module 'mongoose' {
320
328
  * with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
321
329
  * and [views](https://docs.mongodb.com/manual/core/views/) from mongoose.
322
330
  */
323
- createCollection(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection>;
324
- createCollection(name: string, cb: Callback<mongodb.Collection>): void;
325
- createCollection(name: string, options: mongodb.CreateCollectionOptions, cb?: Callback<mongodb.Collection>): Promise<mongodb.Collection>;
331
+ createCollection<T = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
332
+ createCollection<T = AnyObject>(name: string, cb: Callback<mongodb.Collection<T>>): void;
333
+ createCollection<T = AnyObject>(name: string, options: mongodb.CreateCollectionOptions, cb?: Callback<mongodb.Collection<T>>): Promise<mongodb.Collection<T>>;
326
334
 
327
335
  /**
328
336
  * Removes the model named `name` from this connection, if it exists. You can
@@ -442,8 +450,8 @@ declare module 'mongoose' {
442
450
  * the model's schema except the `_id` index, and build any indexes that
443
451
  * are in your schema but not in MongoDB.
444
452
  */
445
- syncIndexes(options?: Record<string, unknown>): Promise<Array<string>>;
446
- syncIndexes(options: Record<string, unknown> | null, callback: Callback<Array<string>>): void;
453
+ syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
454
+ syncIndexes(options: SyncIndexesOptions | null, callback: Callback<ConnectionSyncIndexesResult>): void;
447
455
 
448
456
  /**
449
457
  * _Requires MongoDB >= 3.6.0._ Executes the wrapped async function
@@ -467,7 +475,7 @@ declare module 'mongoose' {
467
475
  * section collection.js
468
476
  * http://mongoosejs.com/docs/api.html#collection-js
469
477
  */
470
- interface CollectionBase extends mongodb.Collection {
478
+ interface CollectionBase<T> extends mongodb.Collection<T> {
471
479
  /*
472
480
  * Abstract methods. Some of these are already defined on the
473
481
  * mongodb.Collection interface so they've been commented out.
@@ -489,7 +497,7 @@ declare module 'mongoose' {
489
497
  * http://mongoosejs.com/docs/api.html#drivers-node-mongodb-native-collection-js
490
498
  */
491
499
  let Collection: Collection;
492
- interface Collection extends CollectionBase {
500
+ interface Collection<T = AnyObject> extends CollectionBase<T> {
493
501
  /**
494
502
  * Collection constructor
495
503
  * @param name name of the collection
@@ -497,7 +505,7 @@ declare module 'mongoose' {
497
505
  * @param opts optional collection options
498
506
  */
499
507
  // eslint-disable-next-line @typescript-eslint/no-misused-new
500
- new(name: string, conn: Connection, opts?: any): Collection;
508
+ new(name: string, conn: Connection, opts?: any): Collection<T>;
501
509
  /** Formatter for debug print args */
502
510
  $format(arg: any): string;
503
511
  /** Debug print helper */
@@ -759,7 +767,7 @@ declare module 'mongoose' {
759
767
 
760
768
  type Require_id<T> = T extends { _id?: any } ? (T & { _id: T['_id'] }) : (T & { _id: Types.ObjectId });
761
769
 
762
- export type HydratedDocument<DocType, TMethods = {}, TVirtuals = {}> = DocType extends Document ? Require_id<DocType> : (Document<unknown, any, DocType> & Require_id<DocType> & TVirtuals & TMethods);
770
+ export type HydratedDocument<DocType, TMethodsAndOverrides = {}, TVirtuals = {}> = DocType extends Document ? Require_id<DocType> : (Document<unknown, any, DocType> & Require_id<DocType> & TVirtuals & TMethodsAndOverrides);
763
771
 
764
772
  interface IndexesDiff {
765
773
  /** Indexes that would be created in mongodb. */
@@ -768,9 +776,15 @@ declare module 'mongoose' {
768
776
  toDrop: Array<any>
769
777
  }
770
778
 
779
+ interface ModifyResult<T> {
780
+ value: Require_id<T> | null;
781
+ lastErrorObject?: mongodb.Document;
782
+ ok: 0 | 1;
783
+ }
784
+
771
785
  export const Model: Model<any>;
772
- interface Model<T, TQueryHelpers = {}, TMethods = {}, TVirtuals = {}> extends NodeJS.EventEmitter, AcceptsDiscriminator {
773
- new<DocType = AnyKeys<T> & AnyObject>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<T, TMethods, TVirtuals>;
786
+ interface Model<T, TQueryHelpers = {}, TMethodsAndOverrides = {}, TVirtuals = {}> extends NodeJS.EventEmitter, AcceptsDiscriminator {
787
+ new<DocType = AnyKeys<T> & AnyObject>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<T, TMethodsAndOverrides, TVirtuals>;
774
788
 
775
789
  aggregate<R = any>(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
776
790
  aggregate<R = any>(pipeline: PipelineStage[], cb: Function): Aggregate<Array<R>>;
@@ -799,37 +813,37 @@ declare module 'mongoose' {
799
813
  * sending multiple `save()` calls because with `bulkSave()` there is only one
800
814
  * network round trip to the MongoDB server.
801
815
  */
802
- bulkSave(documents: Array<Document>): Promise<mongodb.BulkWriteResult>;
816
+ bulkSave(documents: Array<Document>, options?: mongodb.BulkWriteOptions): Promise<mongodb.BulkWriteResult>;
803
817
 
804
818
  /** Collection the model uses. */
805
819
  collection: Collection;
806
820
 
807
821
  /** Creates a `count` query: counts the number of documents that match `filter`. */
808
- count(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
809
- count(filter: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
822
+ count(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
823
+ count(filter: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
810
824
 
811
825
  /** Creates a `countDocuments` query: counts the number of documents that match `filter`. */
812
- countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
813
- countDocuments(filter: FilterQuery<T>, options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
826
+ countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
827
+ countDocuments(filter: FilterQuery<T>, options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
814
828
 
815
829
  /** Creates a new document or documents */
816
- create(docs: (AnyKeys<T> | AnyObject)[], options?: SaveOptions): Promise<HydratedDocument<T, TMethods, TVirtuals>[]>;
817
- create(docs: (AnyKeys<T> | AnyObject)[], callback: Callback<HydratedDocument<T, TMethods, TVirtuals>[]>): void;
818
- create(doc: AnyKeys<T> | AnyObject): Promise<HydratedDocument<T, TMethods, TVirtuals>>;
819
- create(doc: AnyKeys<T> | AnyObject, callback: Callback<HydratedDocument<T, TMethods, TVirtuals>>): void;
820
- create<DocContents = AnyKeys<T>>(docs: DocContents[], options?: SaveOptions): Promise<HydratedDocument<T, TMethods, TVirtuals>[]>;
821
- create<DocContents = AnyKeys<T>>(docs: DocContents[], callback: Callback<HydratedDocument<T, TMethods, TVirtuals>[]>): void;
822
- create<DocContents = AnyKeys<T>>(doc: DocContents): Promise<HydratedDocument<T, TMethods, TVirtuals>>;
823
- create<DocContents = AnyKeys<T>>(...docs: DocContents[]): Promise<HydratedDocument<T, TMethods, TVirtuals>[]>;
824
- create<DocContents = AnyKeys<T>>(doc: DocContents, callback: Callback<HydratedDocument<T, TMethods, TVirtuals>>): void;
830
+ create(docs: (AnyKeys<T> | AnyObject)[], options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
831
+ create(docs: (AnyKeys<T> | AnyObject)[], callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
832
+ create(doc: AnyKeys<T> | AnyObject): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
833
+ create(doc: AnyKeys<T> | AnyObject, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
834
+ create<DocContents = AnyKeys<T>>(docs: DocContents[], options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
835
+ create<DocContents = AnyKeys<T>>(docs: DocContents[], callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
836
+ create<DocContents = AnyKeys<T>>(doc: DocContents): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
837
+ create<DocContents = AnyKeys<T>>(...docs: DocContents[]): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
838
+ create<DocContents = AnyKeys<T>>(doc: DocContents, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
825
839
 
826
840
  /**
827
841
  * Create the collection for this model. By default, if no indexes are specified,
828
842
  * mongoose will not create the collection for the model until any documents are
829
843
  * created. Use this method to create the collection explicitly.
830
844
  */
831
- createCollection(options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection>;
832
- createCollection(options: mongodb.CreateCollectionOptions | null, callback: Callback<mongodb.Collection>): void;
845
+ createCollection<T>(options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
846
+ createCollection<T>(options: mongodb.CreateCollectionOptions | null, callback: Callback<mongodb.Collection<T>>): void;
833
847
 
834
848
  /**
835
849
  * Similar to `ensureIndexes()`, except for it uses the [`createIndex`](http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#createIndex)
@@ -846,18 +860,18 @@ declare module 'mongoose' {
846
860
  * Behaves like `remove()`, but deletes all documents that match `conditions`
847
861
  * regardless of the `single` option.
848
862
  */
849
- deleteMany(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
850
- deleteMany(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
851
- deleteMany(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
863
+ deleteMany(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
864
+ deleteMany(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
865
+ deleteMany(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
852
866
 
853
867
  /**
854
868
  * Deletes the first document that matches `conditions` from the collection.
855
869
  * Behaves like `remove()`, but deletes at most one document regardless of the
856
870
  * `single` option.
857
871
  */
858
- deleteOne(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
859
- deleteOne(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
860
- deleteOne(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
872
+ deleteOne(filter?: FilterQuery<T>, options?: QueryOptions, callback?: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
873
+ deleteOne(filter: FilterQuery<T>, callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
874
+ deleteOne(callback: CallbackWithoutResult): QueryWithHelpers<mongodb.DeleteResult, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
861
875
 
862
876
  /**
863
877
  * Sends `createIndex` commands to mongo for each index declared in the schema.
@@ -877,16 +891,16 @@ declare module 'mongoose' {
877
891
  * equivalent to `findOne({ _id: id })`. If you want to query by a document's
878
892
  * `_id`, use `findById()` instead of `findOne()`.
879
893
  */
880
- findById(id: any, projection?: any | null, options?: QueryOptions | null, callback?: Callback<HydratedDocument<T, TMethods, TVirtuals> | null>): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals> | null, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
894
+ findById<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: any, projection?: any | null, options?: QueryOptions | null, callback?: Callback<ResultDoc | null>): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
881
895
 
882
896
  /** Finds one document. */
883
- findOne(filter?: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: Callback<HydratedDocument<T, TMethods, TVirtuals> | null>): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals> | null, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
897
+ findOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: Callback<ResultDoc | null>): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
884
898
 
885
899
  /**
886
900
  * Shortcut for creating a new Document from existing raw data, pre-saved in the DB.
887
901
  * The document returned has no paths marked as modified initially.
888
902
  */
889
- hydrate(obj: any): HydratedDocument<T, TMethods, TVirtuals>;
903
+ hydrate(obj: any): HydratedDocument<T, TMethodsAndOverrides, TVirtuals>;
890
904
 
891
905
  /**
892
906
  * This function is responsible for building [indexes](https://docs.mongodb.com/manual/indexes/),
@@ -896,15 +910,15 @@ declare module 'mongoose' {
896
910
  * [`connection.model()`](/docs/api.html#connection_Connection-model), so you
897
911
  * don't need to call it.
898
912
  */
899
- init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T, TMethods, TVirtuals>>;
913
+ init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
900
914
 
901
915
  /** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
902
916
  insertMany(docs: Array<AnyKeys<T> | AnyObject>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
903
- insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions): Promise<Array<HydratedDocument<T, TMethods, TVirtuals>>>;
917
+ insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
904
918
  insertMany(doc: AnyKeys<T> | AnyObject, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
905
- insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions): Promise<HydratedDocument<T, TMethods, TVirtuals>[]>;
906
- insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T, TMethods, TVirtuals>[] | InsertManyResult>): void;
907
- insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T, TMethods, TVirtuals>> | InsertManyResult>): void;
919
+ insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
920
+ insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[] | InsertManyResult>): void;
921
+ insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>> | InsertManyResult>): void;
908
922
 
909
923
  /**
910
924
  * Lists the indexes currently defined in MongoDB. This may or may not be
@@ -920,9 +934,9 @@ declare module 'mongoose' {
920
934
 
921
935
  /** Populates document references. */
922
936
  populate(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string,
923
- callback?: Callback<(HydratedDocument<T, TMethods, TVirtuals>)[]>): Promise<Array<HydratedDocument<T, TMethods, TVirtuals>>>;
937
+ callback?: Callback<(HydratedDocument<T, TMethodsAndOverrides, TVirtuals>)[]>): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
924
938
  populate(doc: any, options: PopulateOptions | Array<PopulateOptions> | string,
925
- callback?: Callback<HydratedDocument<T, TMethods, TVirtuals>>): Promise<HydratedDocument<T, TMethods, TVirtuals>>;
939
+ callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
926
940
 
927
941
  /**
928
942
  * Makes the indexes in MongoDB match the indexes defined in this model's
@@ -957,7 +971,7 @@ declare module 'mongoose' {
957
971
  watch<ResultType = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
958
972
 
959
973
  /** Adds a `$where` clause to this query */
960
- $where(argument: string | Function): QueryWithHelpers<Array<HydratedDocument<T, TMethods, TVirtuals>>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
974
+ $where(argument: string | Function): QueryWithHelpers<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
961
975
 
962
976
  /** Registered discriminators for this model. */
963
977
  discriminators: { [name: string]: Model<any> } | undefined;
@@ -966,51 +980,51 @@ declare module 'mongoose' {
966
980
  translateAliases(raw: any): any;
967
981
 
968
982
  /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
969
- distinct(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<any>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
983
+ distinct(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<any>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
970
984
 
971
985
  /** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
972
- estimatedDocumentCount(options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
986
+ estimatedDocumentCount(options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
973
987
 
974
988
  /**
975
- * Returns true if at least one document exists in the database that matches
976
- * the given `filter`, and false otherwise.
989
+ * Returns a document with its `_id` if at least one document exists in the database that matches
990
+ * the given `filter`, and `null` otherwise.
977
991
  */
978
- exists(filter: FilterQuery<T>): Promise<boolean>;
979
- exists(filter: FilterQuery<T>, callback: Callback<boolean>): void;
992
+ exists(filter: FilterQuery<T>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
993
+ exists(filter: FilterQuery<T>, callback: Callback<Pick<Document<T>, '_id'> | null>): QueryWithHelpers<Pick<Document<T>, '_id'> | null, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
980
994
 
981
995
  /** Creates a `find` query: gets a list of documents that match `filter`. */
982
- find(callback?: Callback<HydratedDocument<T, TMethods, TVirtuals>[]>): QueryWithHelpers<Array<HydratedDocument<T, TMethods, TVirtuals>>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
983
- find(filter: FilterQuery<T>, callback?: Callback<T[]>): QueryWithHelpers<Array<HydratedDocument<T, TMethods, TVirtuals>>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
984
- find(filter: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: Callback<HydratedDocument<T, TMethods, TVirtuals>[]>): QueryWithHelpers<Array<HydratedDocument<T, TMethods, TVirtuals>>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
996
+ find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
997
+ find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
998
+ find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: Callback<ResultDoc[]>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
985
999
 
986
1000
  /** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
987
- findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: HydratedDocument<T, TMethods, TVirtuals> | null, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals> | null, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1001
+ findByIdAndDelete<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
988
1002
 
989
1003
  /** Creates a `findByIdAndRemove` query, filtering by the given `_id`. */
990
- findByIdAndRemove(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: HydratedDocument<T, TMethods, TVirtuals> | null, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals> | null, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1004
+ findByIdAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
991
1005
 
992
1006
  /** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
993
- findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<mongodb.ModifyResult<HydratedDocument<T, TMethods, TVirtuals>>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
994
- findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: HydratedDocument<T, TMethods, TVirtuals>, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
995
- findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: HydratedDocument<T, TMethods, TVirtuals> | null, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals> | null, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
996
- findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<T>, callback: (err: CallbackError, doc: HydratedDocument<T, TMethods, TVirtuals> | null, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals> | null, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1007
+ findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
1008
+ findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
1009
+ findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id?: mongodb.ObjectId | any, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
1010
+ findByIdAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(id: mongodb.ObjectId | any, update: UpdateQuery<T>, callback: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
997
1011
 
998
1012
  /** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
999
- findOneAndDelete(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: HydratedDocument<T, TMethods, TVirtuals> | null, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals> | null, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1013
+ findOneAndDelete<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
1000
1014
 
1001
1015
  /** Creates a `findOneAndRemove` query: atomically finds the given document and deletes it. */
1002
- findOneAndRemove(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: HydratedDocument<T, TMethods, TVirtuals> | null, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals> | null, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1016
+ findOneAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
1003
1017
 
1004
1018
  /** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
1005
- findOneAndReplace(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: HydratedDocument<T, TMethods, TVirtuals>, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1006
- findOneAndReplace(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: (err: CallbackError, doc: HydratedDocument<T, TMethods, TVirtuals> | null, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals> | null, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1019
+ findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
1020
+ findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
1007
1021
 
1008
1022
  /** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
1009
- findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<mongodb.ModifyResult<HydratedDocument<T, TMethods, TVirtuals>>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1010
- findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: HydratedDocument<T, TMethods, TVirtuals>, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1011
- findOneAndUpdate(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: T | null, res: any) => void): QueryWithHelpers<HydratedDocument<T, TMethods, TVirtuals> | null, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1023
+ findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, update: UpdateQuery<T>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
1024
+ findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, update: UpdateQuery<T>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
1025
+ findOneAndUpdate<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: T | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
1012
1026
 
1013
- geoSearch(filter?: FilterQuery<T>, options?: GeoSearchOptions, callback?: Callback<Array<HydratedDocument<T, TMethods, TVirtuals>>>): QueryWithHelpers<Array<HydratedDocument<T, TMethods, TVirtuals>>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1027
+ geoSearch<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: GeoSearchOptions, callback?: Callback<Array<ResultDoc>>): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
1014
1028
 
1015
1029
  /** Executes a mapReduce command. */
1016
1030
  mapReduce<Key, Value>(
@@ -1018,11 +1032,11 @@ declare module 'mongoose' {
1018
1032
  callback?: Callback
1019
1033
  ): Promise<any>;
1020
1034
 
1021
- remove(filter?: any, callback?: CallbackWithoutResult): QueryWithHelpers<any, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1035
+ remove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: any, callback?: CallbackWithoutResult): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
1022
1036
 
1023
1037
  /** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */
1024
- replaceOne(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1025
- replaceOne(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1038
+ replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
1039
+ replaceOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<any, ResultDoc, TQueryHelpers, T>;
1026
1040
 
1027
1041
  /** Schema the model uses. */
1028
1042
  schema: Schema<T>;
@@ -1031,18 +1045,18 @@ declare module 'mongoose' {
1031
1045
  * @deprecated use `updateOne` or `updateMany` instead.
1032
1046
  * Creates a `update` query: updates one or many documents that match `filter` with `update`, based on the `multi` option.
1033
1047
  */
1034
- update(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1048
+ update<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
1035
1049
 
1036
1050
  /** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
1037
- updateMany(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1051
+ updateMany<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
1038
1052
 
1039
1053
  /** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */
1040
- updateOne(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1054
+ updateOne<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, T>;
1041
1055
 
1042
1056
  /** Creates a Query, applies the passed conditions, and returns the Query. */
1043
- where(path: string, val?: any): QueryWithHelpers<Array<HydratedDocument<T, TMethods, TVirtuals>>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1044
- where(obj: object): QueryWithHelpers<Array<HydratedDocument<T, TMethods, TVirtuals>>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1045
- where(): QueryWithHelpers<Array<HydratedDocument<T, TMethods, TVirtuals>>, HydratedDocument<T, TMethods, TVirtuals>, TQueryHelpers, T>;
1057
+ where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(path: string, val?: any): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
1058
+ where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(obj: object): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
1059
+ where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
1046
1060
  }
1047
1061
 
1048
1062
  type UpdateWriteOpResult = mongodb.UpdateResult;
@@ -1408,6 +1422,7 @@ declare module 'mongoose' {
1408
1422
  type StringSchemaDefinition = typeof String | 'string' | 'String' | typeof Schema.Types.String;
1409
1423
  type BooleanSchemaDefinition = typeof Boolean | 'boolean' | 'Boolean' | typeof Schema.Types.Boolean;
1410
1424
  type DateSchemaDefinition = typeof NativeDate | 'date' | 'Date' | typeof Schema.Types.Date;
1425
+ type ObjectIdSchemaDefinition = 'ObjectId' | 'ObjectID' | typeof Schema.Types.ObjectId;
1411
1426
 
1412
1427
  type SchemaDefinitionWithBuiltInClass<T> = T extends number
1413
1428
  ? NumberSchemaDefinition
@@ -1505,6 +1520,11 @@ declare module 'mongoose' {
1505
1520
  * optimistic concurrency.
1506
1521
  */
1507
1522
  optimisticConcurrency?: boolean;
1523
+ /**
1524
+ * If `plugin()` called with tags, Mongoose will only apply plugins to schemas that have
1525
+ * a matching tag in `pluginTags`
1526
+ */
1527
+ pluginTags?: string[];
1508
1528
  /**
1509
1529
  * Allows setting query#read options at the schema level, providing us a way to apply default ReadPreferences
1510
1530
  * to all queries derived from a model.
@@ -1603,6 +1623,8 @@ declare module 'mongoose' {
1603
1623
  T extends NativeDate ? DateSchemaDefinition :
1604
1624
  T extends Map<any, any> ? SchemaDefinition<typeof Map> :
1605
1625
  T extends Buffer ? SchemaDefinition<typeof Buffer> :
1626
+ T extends Types.ObjectId ? ObjectIdSchemaDefinition :
1627
+ T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId>> :
1606
1628
  T extends object[] ? (AnyArray<Schema<any, any, any>> | AnyArray<SchemaDefinition<Unpacked<T>>> | AnyArray<SchemaTypeOptions<Unpacked<T>>>) :
1607
1629
  T extends string[] ? AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string>> :
1608
1630
  T extends number[] ? AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number>> :
@@ -1808,6 +1830,8 @@ declare module 'mongoose' {
1808
1830
  validator: ValidateFn<T> | LegacyAsyncValidateFn<T> | AsyncValidateFn<T>;
1809
1831
  }
1810
1832
 
1833
+ type InferId<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
1834
+
1811
1835
  interface VirtualTypeOptions {
1812
1836
  /** If `ref` is not nullish, this becomes a populated virtual. */
1813
1837
  ref?: string | Function;
@@ -2076,17 +2100,17 @@ declare module 'mongoose' {
2076
2100
 
2077
2101
  class Decimal128 extends mongodb.Decimal128 { }
2078
2102
 
2079
- class DocumentArray<T> extends Types.Array<T> {
2103
+ class DocumentArray<T> extends Types.Array<T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T> {
2080
2104
  /** DocumentArray constructor */
2081
2105
  constructor(values: any[]);
2082
2106
 
2083
2107
  isMongooseDocumentArray: true;
2084
2108
 
2085
2109
  /** Creates a subdocument casted to this schema. */
2086
- create(obj: any): T;
2110
+ create(obj: any): T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T;
2087
2111
 
2088
2112
  /** Searches array items for the first document with a matching _id. */
2089
- id(id: any): T | null;
2113
+ id(id: any): (T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T) | null;
2090
2114
 
2091
2115
  push(...args: (AnyKeys<T> & AnyObject)[]): number;
2092
2116
  }
@@ -2126,6 +2150,8 @@ declare module 'mongoose' {
2126
2150
  type UnpackedIntersection<T, U> = T extends (infer V)[] ? (V & U)[] : T & U;
2127
2151
  type UnpackedIntersectionWithNull<T, U> = T extends null ? UnpackedIntersection<T, U> | null : UnpackedIntersection<T, U>;
2128
2152
 
2153
+ type ProjectionFields<DocType> = {[Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any} & Record<string, any>;
2154
+
2129
2155
  class Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {
2130
2156
  _mongooseOptions: MongooseQueryOptions;
2131
2157
 
@@ -2269,9 +2295,24 @@ declare module 'mongoose' {
2269
2295
  findOneAndRemove(filter?: FilterQuery<DocType>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
2270
2296
 
2271
2297
  /** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
2272
- findOneAndUpdate(filter: FilterQuery<DocType>, update: UpdateQuery<DocType>, options: QueryOptions & { rawResult: true }, callback?: (err: CallbackError, doc: DocType | null, res: mongodb.ModifyResult<DocType>) => void): QueryWithHelpers<mongodb.ModifyResult<DocType>, DocType, THelpers, RawDocType>;
2273
- findOneAndUpdate(filter: FilterQuery<DocType>, update: UpdateQuery<DocType>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: DocType, res: mongodb.ModifyResult<DocType>) => void): QueryWithHelpers<DocType, DocType, THelpers, RawDocType>;
2274
- findOneAndUpdate(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: CallbackError, doc: DocType | null, res: mongodb.ModifyResult<DocType>) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
2298
+ findOneAndUpdate(
2299
+ filter: FilterQuery<DocType>,
2300
+ update: UpdateQuery<DocType>,
2301
+ options: QueryOptions & { rawResult: true },
2302
+ callback?: (err: CallbackError, doc: DocType | null, res: ModifyResult<DocType>) => void
2303
+ ): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType>;
2304
+ findOneAndUpdate(
2305
+ filter: FilterQuery<DocType>,
2306
+ update: UpdateQuery<DocType>,
2307
+ options: QueryOptions & { upsert: true } & ReturnsNewDoc,
2308
+ callback?: (err: CallbackError, doc: DocType, res: ModifyResult<DocType>) => void
2309
+ ): QueryWithHelpers<DocType, DocType, THelpers, RawDocType>;
2310
+ findOneAndUpdate(
2311
+ filter?: FilterQuery<DocType>,
2312
+ update?: UpdateQuery<DocType>,
2313
+ options?: QueryOptions | null,
2314
+ callback?: (err: CallbackError, doc: DocType | null, res: ModifyResult<DocType>) => void
2315
+ ): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
2275
2316
 
2276
2317
  /** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
2277
2318
  findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: CallbackError, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType>;
@@ -2412,7 +2453,9 @@ declare module 'mongoose' {
2412
2453
  populate<Paths = {}>(options: PopulateOptions | Array<PopulateOptions>): QueryWithHelpers<UnpackedIntersectionWithNull<ResultType, Paths>, DocType, THelpers, RawDocType>;
2413
2454
 
2414
2455
  /** Get/set the current projection (AKA fields). Pass `null` to remove the current projection. */
2415
- projection(fields?: any | null): this;
2456
+ projection(): ProjectionFields<DocType> | null;
2457
+ projection(fields: null): null;
2458
+ projection(fields?: ProjectionFields<DocType> | string): ProjectionFields<DocType>;
2416
2459
 
2417
2460
  /** Determines the MongoDB nodes from which to read. */
2418
2461
  read(pref: string | mongodb.ReadPreferenceMode, tags?: any[]): this;
@@ -2957,272 +3000,6 @@ declare module 'mongoose' {
2957
3000
  next(callback: Callback): void;
2958
3001
  }
2959
3002
 
2960
- /**
2961
- * [Stages reference](https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/#aggregation-pipeline-stages)
2962
- */
2963
- export type PipelineStage =
2964
- | PipelineStage.AddFields
2965
- | PipelineStage.Bucket
2966
- | PipelineStage.BucketAuto
2967
- | PipelineStage.CollStats
2968
- | PipelineStage.Count
2969
- | PipelineStage.Facet
2970
- | PipelineStage.GeoNear
2971
- | PipelineStage.GraphLookup
2972
- | PipelineStage.Group
2973
- | PipelineStage.IndexStats
2974
- | PipelineStage.Limit
2975
- | PipelineStage.ListSessions
2976
- | PipelineStage.Lookup
2977
- | PipelineStage.Match
2978
- | PipelineStage.Merge
2979
- | PipelineStage.Out
2980
- | PipelineStage.PlanCacheStats
2981
- | PipelineStage.Project
2982
- | PipelineStage.Redact
2983
- | PipelineStage.ReplaceRoot
2984
- | PipelineStage.ReplaceWith
2985
- | PipelineStage.Sample
2986
- | PipelineStage.Search
2987
- | PipelineStage.Set
2988
- | PipelineStage.SetWindowFields
2989
- | PipelineStage.Skip
2990
- | PipelineStage.Sort
2991
- | PipelineStage.SortByCount
2992
- | PipelineStage.UnionWith
2993
- | PipelineStage.Unset
2994
- | PipelineStage.Unwind
2995
-
2996
- export namespace PipelineStage {
2997
- export interface AddFields {
2998
- /** [`$addFields` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/addFields/) */
2999
- $addFields: Record<string, any>
3000
- }
3001
-
3002
- export interface Bucket {
3003
- /** [`$bucket` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/bucket/) */
3004
- $bucket: {
3005
- groupBy: any
3006
- boundaries: any[]
3007
- default?: any
3008
- output?: Record<string, { [op in AccumulatorOperator]?: any }>
3009
- }
3010
- }
3011
-
3012
- export interface BucketAuto {
3013
- /** [`$bucketAuto` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/) */
3014
- $bucketAuto: {
3015
- groupBy: any
3016
- buckets: number
3017
- output?: Record<string, { [op in AccumulatorOperator]?: any }>
3018
- granularity?: 'R5' | 'R10' | 'R20' | 'R40' | 'R80' | '1-2-5' | 'E6' | 'E12' | 'E24' | 'E48' | 'E96' | 'E192' | 'POWERSOF2'
3019
- }
3020
- }
3021
-
3022
- export interface CollStats {
3023
- /** [`$collStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/collStats/) */
3024
- $collStats: {
3025
- latencyStats?: { histograms?: boolean }
3026
- storageStats?: { scale?: number }
3027
- count?: {}
3028
- queryExecStats?: {}
3029
- }
3030
- }
3031
-
3032
- export interface Count {
3033
- /** [`$count` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/count/) */
3034
- $count: string
3035
- }
3036
-
3037
- export interface Facet {
3038
- /** [`$facet` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/facet/) */
3039
- $facet: Record<string, FacetPipelineStage[]>
3040
- }
3041
-
3042
- export type FacetPipelineStage = Exclude<PipelineStage, PipelineStage.CollStats | PipelineStage.Facet | PipelineStage.GeoNear | PipelineStage.IndexStats | PipelineStage.Out | PipelineStage.Merge | PipelineStage.PlanCacheStats>
3043
-
3044
- export interface GeoNear {
3045
- /** [`$geoNear` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/) */
3046
- $geoNear: {
3047
- near: { type: 'Point'; coordinates: [number, number] } | [number, number]
3048
- distanceField: string
3049
- distanceMultiplier?: number
3050
- includeLocs?: string
3051
- key?: string
3052
- maxDistance?: number
3053
- minDistance?: number
3054
- query?: AnyObject
3055
- spherical?: boolean
3056
- uniqueDocs?: boolean
3057
- }
3058
- }
3059
-
3060
- export interface GraphLookup {
3061
- /** [`$graphLookup` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/) */
3062
- $graphLookup: {
3063
- from: string
3064
- startWith: any
3065
- connectFromField: string
3066
- connectToField: string
3067
- as: string
3068
- maxDepth?: number
3069
- depthField?: string
3070
- restrictSearchWithMatch?: AnyObject
3071
- }
3072
- }
3073
-
3074
- export interface Group {
3075
- /** [`$group` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/group) */
3076
- $group: { _id: any } | { [key: string]: { [op in AccumulatorOperator]?: any } }
3077
- }
3078
-
3079
- export interface IndexStats {
3080
- /** [`$indexStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/) */
3081
- $indexStats: {}
3082
- }
3083
-
3084
- export interface Limit {
3085
- /** [`$limit` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/limit/) */
3086
- $limit: number
3087
- }
3088
-
3089
- export interface ListSessions {
3090
- /** [`$listSessions` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/listSessions/) */
3091
- $listSessions: { users?: { user: string; db: string }[] } | { allUsers?: true }
3092
- }
3093
-
3094
- export interface Lookup {
3095
- /** [`$lookup` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/) */
3096
- $lookup: {
3097
- from: string
3098
- as: string
3099
- localField?: string
3100
- foreignField?: string
3101
- let?: Record<string, any>
3102
- pipeline?: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out | PipelineStage.Search>[]
3103
- }
3104
- }
3105
-
3106
- export interface Match {
3107
- /** [`$match` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/match/) */
3108
- $match: AnyObject
3109
- }
3110
-
3111
- export interface Merge {
3112
- /** [`$merge` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/merge/) */
3113
- $merge: {
3114
- into: string | { db: string; coll: string }
3115
- on?: string | string[]
3116
- let?: Record<string, any>
3117
- whenMatched?: 'replace' | 'keepExisting' | 'merge' | 'fail' | Extract<PipelineStage, PipelineStage.AddFields | PipelineStage.Set | PipelineStage.Project | PipelineStage.Unset | PipelineStage.ReplaceRoot | PipelineStage.ReplaceWith>[]
3118
- whenNotMatched?: 'insert' | 'discard' | 'fail'
3119
- }
3120
- }
3121
-
3122
- export interface Out {
3123
- /** [`$out` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/out/) */
3124
- $out: string | { db: string; coll: string }
3125
- }
3126
-
3127
- export interface PlanCacheStats {
3128
- /** [`$planCacheStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/planCacheStats/) */
3129
- $planCacheStats: {}
3130
- }
3131
-
3132
- export interface Project {
3133
- /** [`$project` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/project/) */
3134
- $project: { [field: string]: any }
3135
- }
3136
-
3137
- export interface Redact {
3138
- /** [`$redact` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/redact/) */
3139
- $redact: any
3140
- }
3141
-
3142
- export interface ReplaceRoot {
3143
- /** [`$replaceRoot` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceRoot/) */
3144
- $replaceRoot: { newRoot: any }
3145
- }
3146
-
3147
- export interface ReplaceWith {
3148
- /** [`$replaceWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceWith/) */
3149
- $replaceWith: any
3150
- }
3151
-
3152
- export interface Sample {
3153
- /** [`$sample` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sample/) */
3154
- $sample: { size: number }
3155
- }
3156
-
3157
- export interface Search {
3158
- /** [`$search` reference](https://docs.atlas.mongodb.com/reference/atlas-search/query-syntax/) */
3159
- $search: {
3160
- [key: string]: any
3161
- index?: string
3162
- highlight?: { path: string; maxCharsToExamine?: number; maxNumPassages?: number }
3163
- }
3164
- }
3165
-
3166
- export interface Set {
3167
- /** [`$set` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/set/) */
3168
- $set: Record<string, any>
3169
- }
3170
-
3171
- export interface SetWindowFields {
3172
- /** [`$setWindowFields` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/setWindowFields/) */
3173
- $setWindowFields: {
3174
- partitionBy?: any
3175
- sortBy?: Record<string, 1 | -1>
3176
- output: Record<
3177
- string,
3178
- { [op in WindowOperator]?: any } & {
3179
- window?: {
3180
- documents?: [string | number, string | number]
3181
- range?: [string | number, string | number]
3182
- unit?: 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond'
3183
- }
3184
- }
3185
- >
3186
- }
3187
- }
3188
-
3189
- export interface Skip {
3190
- /** [`$skip` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/skip/) */
3191
- $skip: number
3192
- }
3193
-
3194
- export interface Sort {
3195
- /** [`$sort` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sort/) */
3196
- $sort: Record<string, 1 | -1 | { $meta: 'textScore' }>
3197
- }
3198
-
3199
- export interface SortByCount {
3200
- /** [`$sortByCount` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sortByCount/) */
3201
- $sortByCount: any
3202
- }
3203
-
3204
- export interface UnionWith {
3205
- /** [`$unionWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unionWith/) */
3206
- $unionWith:
3207
- | string
3208
- | { coll: string; pipeline?: Exclude<PipelineStage, PipelineStage.Out | PipelineStage.Merge>[] }
3209
- }
3210
-
3211
- export interface Unset {
3212
- /** [`$unset` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unset/) */
3213
- $unset: string | string[]
3214
- }
3215
-
3216
- export interface Unwind {
3217
- /** [`$unwind` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/) */
3218
- $unwind: string | { path: string; includeArrayIndex?: string; preserveNullAndEmptyArrays?: boolean }
3219
- }
3220
-
3221
- type AccumulatorOperator = '$accumulator' | '$addToSet' | '$avg' | '$count' | '$first' | '$last' | '$max' | '$mergeObjects' | '$min' | '$push' | '$stdDevPop' | '$stdDevSamp' | '$sum'
3222
-
3223
- type WindowOperator = '$addToSet' | '$avg' | '$count' | '$covariancePop' | '$covarianceSamp' | '$derivative' | '$expMovingAvg' | '$integral' | '$max' | '$min' | '$push' | '$stdDevSamp' | '$stdDevPop' | '$sum' | '$first' | '$last' | '$shift' | '$denseRank' | '$documentNumber' | '$rank'
3224
- }
3225
-
3226
3003
  class SchemaType {
3227
3004
  /** SchemaType constructor */
3228
3005
  constructor(path: string, options?: AnyObject, instance?: string);
@@ -3262,9 +3039,15 @@ declare module 'mongoose' {
3262
3039
  /** String representation of what type this is, like 'ObjectID' or 'Number' */
3263
3040
  instance: string;
3264
3041
 
3042
+ /** True if this SchemaType has a required validator. False otherwise. */
3043
+ isRequired?: boolean;
3044
+
3265
3045
  /** The options this SchemaType was instantiated with */
3266
3046
  options: AnyObject;
3267
3047
 
3048
+ /** The path to this SchemaType in a Schema. */
3049
+ path: string;
3050
+
3268
3051
  /**
3269
3052
  * Set the model that this path refers to. This is the option that [populate](https://mongoosejs.com/docs/populate.html)
3270
3053
  * looks at to determine the foreign collection it should query.
@@ -3298,11 +3081,19 @@ declare module 'mongoose' {
3298
3081
  /** Declares an unique index. */
3299
3082
  unique(bool: boolean): this;
3300
3083
 
3084
+ /** The validators that Mongoose should run to validate properties at this SchemaType's path. */
3085
+ validators: { message?: string; type?: string; validator?: Function }[];
3086
+
3301
3087
  /** Adds validator(s) for this document path. */
3302
3088
  validate(obj: RegExp | Function | any, errorMsg?: string,
3303
3089
  type?: string): this;
3304
3090
  }
3305
3091
 
3092
+ export interface SyncIndexesOptions extends mongodb.CreateIndexesOptions {
3093
+ continueOnError?: boolean
3094
+ }
3095
+ export type ConnectionSyncIndexesResult = Record<string, OneCollectionSyncIndexesResult>;
3096
+ type OneCollectionSyncIndexesResult = Array<string> & mongodb.MongoServerError;
3306
3097
  type Callback<T = any> = (error: CallbackError, result: T) => void;
3307
3098
 
3308
3099
  type CallbackWithoutResult = (error: CallbackError) => void;
@@ -3333,6 +3124,12 @@ declare module 'mongoose' {
3333
3124
 
3334
3125
  constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
3335
3126
  }
3127
+ export class SyncIndexesError extends Error {
3128
+ name: 'SyncIndexesError';
3129
+ errors?: Record<string, mongodb.MongoServerError>;
3130
+
3131
+ constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
3132
+ }
3336
3133
 
3337
3134
  export class DisconnectedError extends Error {
3338
3135
  name: 'DisconnectedError';
@@ -3429,3 +3226,5 @@ declare module 'mongoose' {
3429
3226
  /* for ts-mongoose */
3430
3227
  class mquery {}
3431
3228
  }
3229
+
3230
+ export default mongoose;