mongoose 6.2.3 → 6.2.6

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/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- /// <reference path="./Error.d.ts" />
2
- /// <reference path="./PipelineStage.d.ts" />
1
+ /// <reference path="./connection.d.ts" />
2
+ /// <reference path="./cursor.d.ts" />
3
+ /// <reference path="./document.d.ts" />
4
+ /// <reference path="./error.d.ts" />
5
+ /// <reference path="./pipelinestage.d.ts" />
6
+ /// <reference path="./schemaoptions.d.ts" />
3
7
 
4
8
  import events = require('events');
5
9
  import mongodb = require('mongodb');
@@ -8,14 +12,6 @@ import stream = require('stream');
8
12
 
9
13
  declare module 'mongoose' {
10
14
 
11
- export enum ConnectionStates {
12
- disconnected = 0,
13
- connected = 1,
14
- connecting = 2,
15
- disconnecting = 3,
16
- uninitialized = 99,
17
- }
18
-
19
15
  class NativeDate extends global.Date {}
20
16
 
21
17
  /** The Mongoose Date [SchemaType](/docs/schematypes.html). */
@@ -64,9 +60,6 @@ declare module 'mongoose' {
64
60
  /** The various Mongoose SchemaTypes. */
65
61
  export const SchemaTypes: typeof Schema.Types;
66
62
 
67
- /** Expose connection states for user-land */
68
- export const STATES: typeof ConnectionStates;
69
-
70
63
  /** Opens Mongoose's default connection to MongoDB, see [connections docs](https://mongoosejs.com/docs/connections.html) */
71
64
  export function connect(uri: string, options: ConnectOptions, callback: CallbackWithoutResult): void;
72
65
  export function connect(uri: string, callback: CallbackWithoutResult): void;
@@ -100,10 +93,11 @@ declare module 'mongoose' {
100
93
 
101
94
  /** An array containing all models associated with this Mongoose instance. */
102
95
  export const models: Models;
96
+
103
97
  /** Creates a Connection instance. */
98
+ export function createConnection(uri: string, options: ConnectOptions, callback: Callback<Connection>): void;
104
99
  export function createConnection(uri: string, options?: ConnectOptions): Connection;
105
100
  export function createConnection(): Connection;
106
- export function createConnection(uri: string, options: ConnectOptions, callback: Callback<Connection>): void;
107
101
 
108
102
  /**
109
103
  * Removes the model named `name` from the default connection, if it exists.
@@ -128,6 +122,13 @@ declare module 'mongoose' {
128
122
  export function isValidObjectId(v: Types.ObjectId): true;
129
123
  export function isValidObjectId(v: any): boolean;
130
124
 
125
+ /**
126
+ * Returns true if the given value is a Mongoose ObjectId (using `instanceof`) or if the
127
+ * given value is a 24 character hex string, which is the most commonly used string representation
128
+ * of an ObjectId.
129
+ */
130
+ export function isObjectIdOrHexString(v: any): boolean;
131
+
131
132
  export function model<T>(name: string, schema?: Schema<T, any, any> | Schema<T & Document, any, any>, collection?: string, options?: CompileModelOptions): Model<T>;
132
133
  export function model<T, U, TQueryHelpers = {}>(
133
134
  name: string,
@@ -288,190 +289,6 @@ declare module 'mongoose' {
288
289
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
289
290
  interface ClientSession extends mongodb.ClientSession { }
290
291
 
291
- interface ConnectOptions extends mongodb.MongoClientOptions {
292
- /** Set to false to [disable buffering](http://mongoosejs.com/docs/faq.html#callback_never_executes) on all models associated with this connection. */
293
- bufferCommands?: boolean;
294
- /** The name of the database you want to use. If not provided, Mongoose uses the database name from connection string. */
295
- dbName?: string;
296
- /** username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility. */
297
- user?: string;
298
- /** password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility. */
299
- pass?: string;
300
- /** Set to false to disable automatic index creation for all models associated with this connection. */
301
- autoIndex?: boolean;
302
- /** Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection. */
303
- autoCreate?: boolean;
304
- }
305
-
306
- class Connection extends events.EventEmitter {
307
- /** Returns a promise that resolves when this connection successfully connects to MongoDB */
308
- asPromise(): Promise<this>;
309
-
310
- /** Closes the connection */
311
- close(callback: CallbackWithoutResult): void;
312
- close(force: boolean, callback: CallbackWithoutResult): void;
313
- close(force?: boolean): Promise<void>;
314
-
315
- /** Retrieves a collection, creating it if not cached. */
316
- collection<T = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Collection<T>;
317
-
318
- /** A hash of the collections associated with this connection */
319
- collections: { [index: string]: Collection };
320
-
321
- /** A hash of the global options that are associated with this connection */
322
- config: any;
323
-
324
- /** The mongodb.Db instance, set when the connection is opened */
325
- db: mongodb.Db;
326
-
327
- /**
328
- * Helper for `createCollection()`. Will explicitly create the given collection
329
- * with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
330
- * and [views](https://docs.mongodb.com/manual/core/views/) from mongoose.
331
- */
332
- createCollection<T = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
333
- createCollection<T = AnyObject>(name: string, cb: Callback<mongodb.Collection<T>>): void;
334
- createCollection<T = AnyObject>(name: string, options: mongodb.CreateCollectionOptions, cb?: Callback<mongodb.Collection<T>>): Promise<mongodb.Collection<T>>;
335
-
336
- /**
337
- * Removes the model named `name` from this connection, if it exists. You can
338
- * use this function to clean up any models you created in your tests to
339
- * prevent OverwriteModelErrors.
340
- */
341
- deleteModel(name: string): this;
342
-
343
- /**
344
- * Helper for `dropCollection()`. Will delete the given collection, including
345
- * all documents and indexes.
346
- */
347
- dropCollection(collection: string): Promise<void>;
348
- dropCollection(collection: string, cb: CallbackWithoutResult): void;
349
-
350
- /**
351
- * Helper for `dropDatabase()`. Deletes the given database, including all
352
- * collections, documents, and indexes.
353
- */
354
- dropDatabase(): Promise<void>;
355
- dropDatabase(cb: CallbackWithoutResult): void;
356
-
357
- /** Gets the value of the option `key`. Equivalent to `conn.options[key]` */
358
- get(key: string): any;
359
-
360
- /**
361
- * Returns the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
362
- * that this connection uses to talk to MongoDB.
363
- */
364
- getClient(): mongodb.MongoClient;
365
-
366
- /**
367
- * The host name portion of the URI. If multiple hosts, such as a replica set,
368
- * this will contain the first host name in the URI
369
- */
370
- host: string;
371
-
372
- /**
373
- * A number identifier for this connection. Used for debugging when
374
- * you have [multiple connections](/docs/connections.html#multiple_connections).
375
- */
376
- id: number;
377
-
378
- /**
379
- * A [POJO](https://masteringjs.io/tutorials/fundamentals/pojo) containing
380
- * a map from model names to models. Contains all models that have been
381
- * added to this connection using [`Connection#model()`](/docs/api/connection.html#connection_Connection-model).
382
- */
383
- models: { [index: string]: Model<any> };
384
-
385
- /** Defines or retrieves a model. */
386
- model<T>(name: string, schema?: Schema<any>, collection?: string, options?: CompileModelOptions): Model<T>;
387
- model<T, U, TQueryHelpers = {}>(
388
- name: string,
389
- schema?: Schema<T, U, TQueryHelpers>,
390
- collection?: string,
391
- options?: CompileModelOptions
392
- ): U;
393
-
394
- /** Returns an array of model names created on this connection. */
395
- modelNames(): Array<string>;
396
-
397
- /** The name of the database this connection points to. */
398
- name: string;
399
-
400
- /** Opens the connection with a URI using `MongoClient.connect()`. */
401
- openUri(uri: string, options?: ConnectOptions): Promise<Connection>;
402
- openUri(uri: string, callback: (err: CallbackError, conn?: Connection) => void): Connection;
403
- openUri(uri: string, options: ConnectOptions, callback: (err: CallbackError, conn?: Connection) => void): Connection;
404
-
405
- /** The password specified in the URI */
406
- pass: string;
407
-
408
- /**
409
- * The port portion of the URI. If multiple hosts, such as a replica set,
410
- * this will contain the port from the first host name in the URI.
411
- */
412
- port: number;
413
-
414
- /** Declares a plugin executed on all schemas you pass to `conn.model()` */
415
- plugin(fn: (schema: Schema, opts?: any) => void, opts?: any): Connection;
416
-
417
- /** The plugins that will be applied to all models created on this connection. */
418
- plugins: Array<any>;
419
-
420
- /**
421
- * Connection ready state
422
- *
423
- * - 0 = disconnected
424
- * - 1 = connected
425
- * - 2 = connecting
426
- * - 3 = disconnecting
427
- */
428
- readyState: number;
429
-
430
- /** Sets the value of the option `key`. Equivalent to `conn.options[key] = val` */
431
- set(key: string, value: any): any;
432
-
433
- /**
434
- * Set the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
435
- * that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to
436
- * reuse it.
437
- */
438
- setClient(client: mongodb.MongoClient): this;
439
-
440
- /**
441
- * _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
442
- * for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
443
- * and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
444
- */
445
- startSession(options?: mongodb.ClientSessionOptions): Promise<mongodb.ClientSession>;
446
- startSession(options: mongodb.ClientSessionOptions, cb: Callback<mongodb.ClientSession>): void;
447
-
448
- /**
449
- * Makes the indexes in MongoDB match the indexes defined in every model's
450
- * schema. This function will drop any indexes that are not defined in
451
- * the model's schema except the `_id` index, and build any indexes that
452
- * are in your schema but not in MongoDB.
453
- */
454
- syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
455
- syncIndexes(options: SyncIndexesOptions | null, callback: Callback<ConnectionSyncIndexesResult>): void;
456
-
457
- /**
458
- * _Requires MongoDB >= 3.6.0._ Executes the wrapped async function
459
- * in a transaction. Mongoose will commit the transaction if the
460
- * async function executes successfully and attempt to retry if
461
- * there was a retryable error.
462
- */
463
- transaction(fn: (session: mongodb.ClientSession) => Promise<any>): Promise<any>;
464
-
465
- /** Switches to a different database using the same connection pool. */
466
- useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;
467
-
468
- /** The username specified in the URI */
469
- user: string;
470
-
471
- /** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model.watch). */
472
- watch<ResultType = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
473
- }
474
-
475
292
  /*
476
293
  * section collection.js
477
294
  * http://mongoosejs.com/docs/api.html#collection-js
@@ -515,247 +332,8 @@ declare module 'mongoose' {
515
332
  getIndexes(): any;
516
333
  }
517
334
 
518
- class Document<T = any, TQueryHelpers = any, DocType = any> {
519
- constructor(doc?: any);
520
-
521
- /** This documents _id. */
522
- _id?: T;
523
-
524
- /** This documents __v. */
525
- __v?: any;
526
-
527
- /* Get all subdocs (by bfs) */
528
- $getAllSubdocs(): Document[];
529
-
530
- /** Don't run validation on this path or persist changes to this path. */
531
- $ignore(path: string): void;
532
-
533
- /** Checks if a path is set to its default. */
534
- $isDefault(path: string): boolean;
535
-
536
- /** Getter/setter, determines whether the document was removed or not. */
537
- $isDeleted(val?: boolean): boolean;
538
-
539
- /** Returns an array of all populated documents associated with the query */
540
- $getPopulatedDocs(): Document[];
541
-
542
- /**
543
- * Returns true if the given path is nullish or only contains empty objects.
544
- * Useful for determining whether this subdoc will get stripped out by the
545
- * [minimize option](/docs/guide.html#minimize).
546
- */
547
- $isEmpty(path: string): boolean;
548
-
549
- /** Checks if a path is invalid */
550
- $isValid(path: string): boolean;
551
-
552
- /**
553
- * Empty object that you can use for storing properties on the document. This
554
- * is handy for passing data to middleware without conflicting with Mongoose
555
- * internals.
556
- */
557
- $locals: Record<string, unknown>;
558
-
559
- /** Marks a path as valid, removing existing validation errors. */
560
- $markValid(path: string): void;
561
-
562
- /**
563
- * A string containing the current operation that Mongoose is executing
564
- * on this document. May be `null`, `'save'`, `'validate'`, or `'remove'`.
565
- */
566
- $op: string | null;
567
-
568
- /**
569
- * Getter/setter around the session associated with this document. Used to
570
- * automatically set `session` if you `save()` a doc that you got from a
571
- * query with an associated session.
572
- */
573
- $session(session?: mongodb.ClientSession | null): mongodb.ClientSession;
574
-
575
- /** Alias for `set()`, used internally to avoid conflicts */
576
- $set(path: string, val: any, options?: any): this;
577
- $set(path: string, val: any, type: any, options?: any): this;
578
- $set(value: any): this;
579
-
580
- /** Set this property to add additional query filters when Mongoose saves this document and `isNew` is false. */
581
- $where: Record<string, unknown>;
582
-
583
- /** If this is a discriminator model, `baseModelName` is the name of the base model. */
584
- baseModelName?: string;
585
-
586
- /** Collection the model uses. */
587
- collection: Collection;
588
-
589
- /** Connection the model uses. */
590
- db: Connection;
591
-
592
- /** Removes this document from the db. */
593
- delete(options?: QueryOptions): QueryWithHelpers<any, this, TQueryHelpers>;
594
- delete(options: QueryOptions, cb?: Callback): void;
595
- delete(cb: Callback): void;
596
-
597
- /** Removes this document from the db. */
598
- deleteOne(options?: QueryOptions): QueryWithHelpers<any, this, TQueryHelpers>;
599
- deleteOne(options: QueryOptions, cb?: Callback): void;
600
- deleteOne(cb: Callback): void;
601
-
602
- /**
603
- * Takes a populated field and returns it to its unpopulated state. If called with
604
- * no arguments, then all populated fields are returned to their unpopulated state.
605
- */
606
- depopulate(path?: string | string[]): this;
607
-
608
- /**
609
- * Returns the list of paths that have been directly modified. A direct
610
- * modified path is a path that you explicitly set, whether via `doc.foo = 'bar'`,
611
- * `Object.assign(doc, { foo: 'bar' })`, or `doc.set('foo', 'bar')`.
612
- */
613
- directModifiedPaths(): Array<string>;
614
-
615
- /**
616
- * Returns true if this document is equal to another document.
617
- *
618
- * Documents are considered equal when they have matching `_id`s, unless neither
619
- * document has an `_id`, in which case this function falls back to using
620
- * `deepEqual()`.
621
- */
622
- equals(doc: Document<T>): boolean;
623
-
624
- /** Hash containing current validation errors. */
625
- errors?: Error.ValidationError;
626
-
627
- /** Returns the value of a path. */
628
- get(path: string, type?: any, options?: any): any;
629
-
630
- /**
631
- * Returns the changes that happened to the document
632
- * in the format that will be sent to MongoDB.
633
- */
634
- getChanges(): UpdateQuery<this>;
635
-
636
- /** The string version of this documents _id. */
637
- id?: any;
638
-
639
- /** Signal that we desire an increment of this documents version. */
640
- increment(): this;
641
-
642
- /**
643
- * Initializes the document without setters or marking anything modified.
644
- * Called internally after a document is returned from mongodb. Normally,
645
- * you do **not** need to call this function on your own.
646
- */
647
- init(obj: any, opts?: any, cb?: Callback<this>): this;
648
-
649
- /** Marks a path as invalid, causing validation to fail. */
650
- invalidate(path: string, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null;
651
-
652
- /** Returns true if `path` was directly set and modified, else false. */
653
- isDirectModified(path: string): boolean;
654
-
655
- /** Checks if `path` was explicitly selected. If no projection, always returns true. */
656
- isDirectSelected(path: string): boolean;
657
-
658
- /** Checks if `path` is in the `init` state, that is, it was set by `Document#init()` and not modified since. */
659
- isInit(path: string): boolean;
660
-
661
- /**
662
- * Returns true if any of the given paths is modified, else false. If no arguments, returns `true` if any path
663
- * in this document is modified.
664
- */
665
- isModified(path?: string | Array<string>): boolean;
666
-
667
- /** Boolean flag specifying if the document is new. */
668
- isNew: boolean;
669
-
670
- /** Checks if `path` was selected in the source query which initialized this document. */
671
- isSelected(path: string): boolean;
672
-
673
- /** Marks the path as having pending changes to write to the db. */
674
- markModified(path: string, scope?: any): void;
675
-
676
- /** Returns the list of paths that have been modified. */
677
- modifiedPaths(options?: { includeChildren?: boolean }): Array<string>;
678
-
679
- /** The name of the model */
680
- modelName: string;
681
-
682
- /**
683
- * Overwrite all values in this document with the values of `obj`, except
684
- * for immutable properties. Behaves similarly to `set()`, except for it
685
- * unsets all properties that aren't in `obj`.
686
- */
687
- overwrite(obj: AnyObject): this;
688
-
689
- /**
690
- * If this document is a subdocument or populated document, returns the
691
- * document's parent. Returns undefined otherwise.
692
- */
693
- $parent(): Document | undefined;
694
-
695
- /** Populates document references. */
696
- populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<this & Paths>;
697
- populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<this & Paths>): void;
698
- populate<Paths = {}>(path: string, names: string): Promise<this & Paths>;
699
- populate<Paths = {}>(path: string, names: string, callback: Callback<this & Paths>): void;
700
-
701
- /** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */
702
- populated(path: string): any;
703
-
704
- /** Removes this document from the db. */
705
- remove(options?: QueryOptions): Promise<this>;
706
- remove(options?: QueryOptions, cb?: Callback): void;
707
-
708
- /** Sends a replaceOne command with this document `_id` as the query selector. */
709
- replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
710
- replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
711
-
712
- /** Saves this document by inserting a new document into the database if [document.isNew](/docs/api.html#document_Document-isNew) is `true`, or sends an [updateOne](/docs/api.html#document_Document-updateOne) operation with just the modified paths if `isNew` is `false`. */
713
- save(options?: SaveOptions): Promise<this>;
714
- save(options?: SaveOptions, fn?: Callback<this>): void;
715
- save(fn?: Callback<this>): void;
716
-
717
- /** The document's schema. */
718
- schema: Schema;
719
-
720
- /** Sets the value of a path, or many paths. */
721
- set(path: string, val: any, options?: any): this;
722
- set(path: string, val: any, type: any, options?: any): this;
723
- set(value: any): this;
724
-
725
- /** The return value of this method is used in calls to JSON.stringify(doc). */
726
- toJSON(options: ToObjectOptions & { flattenMaps: false }): LeanDocument<this>;
727
- toJSON(options?: ToObjectOptions): FlattenMaps<LeanDocument<this>>;
728
- toJSON<T = FlattenMaps<DocType>>(options?: ToObjectOptions): T;
729
-
730
- /** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */
731
- toObject(options?: ToObjectOptions): LeanDocument<this>;
732
- toObject<T = DocType>(options?: ToObjectOptions): T;
733
-
734
- /** Clears the modified state on the specified path. */
735
- unmarkModified(path: string): void;
736
-
737
- /** Sends an update command with this document `_id` as the query selector. */
738
- update(update?: UpdateQuery<this> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
739
-
740
- /** Sends an updateOne command with this document `_id` as the query selector. */
741
- updateOne(update?: UpdateQuery<this> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query<any, this>;
742
-
743
- /** Executes registered validation rules for this document. */
744
- validate(options:{ pathsToSkip?: pathsToSkip }): Promise<void>;
745
- validate(pathsToValidate?: pathsToValidate, options?: any): Promise<void>;
746
- validate(callback: CallbackWithoutResult): void;
747
- validate(pathsToValidate: pathsToValidate, callback: CallbackWithoutResult): void;
748
- validate(pathsToValidate: pathsToValidate, options: any, callback: CallbackWithoutResult): void;
749
-
750
- /** Executes registered validation rules (skipping asynchronous validators) for this document. */
751
- validateSync(options:{pathsToSkip?: pathsToSkip, [k:string]: any }): Error.ValidationError | null;
752
- validateSync(pathsToValidate?: Array<string>, options?: any): Error.ValidationError | null;
753
- }
754
-
755
335
  /** A list of paths to validate. If set, Mongoose will validate only the modified paths that are in the given list. */
756
336
  type pathsToValidate = string[] | string;
757
- /** A list of paths to skip. If set, Mongoose will validate every modified path that is not in this list. */
758
- type pathsToSkip = string[] | string;
759
337
 
760
338
  interface AcceptsDiscriminator {
761
339
  /** Adds a discriminator type. */
@@ -981,7 +559,7 @@ declare module 'mongoose' {
981
559
  translateAliases(raw: any): any;
982
560
 
983
561
  /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
984
- distinct(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<any>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
562
+ distinct<ReturnType = any>(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
985
563
 
986
564
  /** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
987
565
  estimatedDocumentCount(options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
@@ -1285,10 +863,10 @@ declare module 'mongoose' {
1285
863
  type IndexDirection = 1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text';
1286
864
  type IndexDefinition = Record<string, IndexDirection>;
1287
865
 
1288
- type PreMiddlewareFunction<T> = (this: T, next: (err?: CallbackError) => void) => void | Promise<void>;
1289
- type PreSaveMiddlewareFunction<T> = (this: T, next: (err?: CallbackError) => void, opts: SaveOptions) => void | Promise<void>;
1290
- type PostMiddlewareFunction<ThisType, ResType = any> = (this: ThisType, res: ResType, next: (err?: CallbackError) => void) => void | Promise<void>;
1291
- type ErrorHandlingMiddlewareFunction<ThisType, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: (err?: CallbackError) => void) => void;
866
+ export type PreMiddlewareFunction<ThisType = any> = (this: ThisType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>;
867
+ export type PreSaveMiddlewareFunction<ThisType = any> = (this: ThisType, next: CallbackWithoutResultAndOptionalError, opts: SaveOptions) => void | Promise<void>;
868
+ export type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>;
869
+ export type ErrorHandlingMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: CallbackWithoutResultAndOptionalError) => void;
1292
870
 
1293
871
  class Schema<DocType = any, M = Model<DocType, any, any, any>, TInstanceMethods = any, TQueryHelpers = any> extends events.EventEmitter {
1294
872
  /**
@@ -1309,6 +887,9 @@ declare module 'mongoose' {
1309
887
  /** Returns a copy of this schema */
1310
888
  clone<T = this>(): T;
1311
889
 
890
+ /** Returns a new schema that has the picked `paths` from this schema. */
891
+ pick<T = this>(paths: string[], options?: SchemaOptions): T;
892
+
1312
893
  /** Object containing discriminators defined on this schema */
1313
894
  discriminators?: { [name: string]: Schema };
1314
895
 
@@ -1416,7 +997,7 @@ declare module 'mongoose' {
1416
997
  statics: { [name: string]: (this: M, ...args: any[]) => any };
1417
998
 
1418
999
  /** Creates a virtual type with the given name. */
1419
- virtual(name: string, options?: VirtualTypeOptions): VirtualType;
1000
+ virtual<T = HydratedDocument<DocType, TInstanceMethods>>(name: string, options?: VirtualTypeOptions<T>): VirtualType;
1420
1001
 
1421
1002
  /** Object of currently defined virtuals on this schema */
1422
1003
  virtuals: any;
@@ -1446,188 +1027,22 @@ declare module 'mongoose' {
1446
1027
  typeof SchemaType |
1447
1028
  Schema<any, any, any> |
1448
1029
  Schema<any, any, any>[] |
1449
- SchemaTypeOptions<T extends undefined ? any : T>[] |
1030
+ SchemaTypeOptions<T extends undefined ? any : Unpacked<T>>[] |
1450
1031
  Function[] |
1451
1032
  SchemaDefinition<T> |
1452
- SchemaDefinition<T>[] |
1033
+ SchemaDefinition<Unpacked<T>>[] |
1453
1034
  typeof SchemaTypes.Mixed;
1454
1035
 
1455
1036
  type SchemaDefinition<T = undefined> = T extends undefined
1456
1037
  ? { [path: string]: SchemaDefinitionProperty; }
1457
1038
  : { [path in keyof T]?: SchemaDefinitionProperty<T[path]>; };
1458
1039
 
1459
- interface SchemaOptions {
1460
- /**
1461
- * By default, Mongoose's init() function creates all the indexes defined in your model's schema by
1462
- * calling Model.createIndexes() after you successfully connect to MongoDB. If you want to disable
1463
- * automatic index builds, you can set autoIndex to false.
1464
- */
1465
- autoIndex?: boolean;
1466
- /**
1467
- * If set to `true`, Mongoose will call Model.createCollection() to create the underlying collection
1468
- * in MongoDB if autoCreate is set to true. Calling createCollection() sets the collection's default
1469
- * collation based on the collation option and establishes the collection as a capped collection if
1470
- * you set the capped schema option.
1471
- */
1472
- autoCreate?: boolean;
1473
- /**
1474
- * By default, mongoose buffers commands when the connection goes down until the driver manages to reconnect.
1475
- * To disable buffering, set bufferCommands to false.
1476
- */
1477
- bufferCommands?: boolean;
1478
- /**
1479
- * If bufferCommands is on, this option sets the maximum amount of time Mongoose buffering will wait before
1480
- * throwing an error. If not specified, Mongoose will use 10000 (10 seconds).
1481
- */
1482
- bufferTimeoutMS?: number;
1483
- /**
1484
- * Mongoose supports MongoDBs capped collections. To specify the underlying MongoDB collection be capped, set
1485
- * the capped option to the maximum size of the collection in bytes.
1486
- */
1487
- capped?: boolean | number | { size?: number; max?: number; autoIndexId?: boolean; };
1488
- /** Sets a default collation for every query and aggregation. */
1489
- collation?: mongodb.CollationOptions;
1490
-
1491
- /** The timeseries option to use when creating the model's collection. */
1492
- timeseries?: mongodb.TimeSeriesCollectionOptions;
1493
-
1494
- /**
1495
- * Mongoose by default produces a collection name by passing the model name to the utils.toCollectionName
1496
- * method. This method pluralizes the name. Set this option if you need a different name for your collection.
1497
- */
1498
- collection?: string;
1499
- /**
1500
- * When you define a [discriminator](/docs/discriminators.html), Mongoose adds a path to your
1501
- * schema that stores which discriminator a document is an instance of. By default, Mongoose
1502
- * adds an `__t` path, but you can set `discriminatorKey` to overwrite this default.
1503
- */
1504
- discriminatorKey?: string;
1505
- /** defaults to false. */
1506
- emitIndexErrors?: boolean;
1507
- excludeIndexes?: any;
1508
- /**
1509
- * Mongoose assigns each of your schemas an id virtual getter by default which returns the document's _id field
1510
- * cast to a string, or in the case of ObjectIds, its hexString.
1511
- */
1512
- id?: boolean;
1513
- /**
1514
- * Mongoose assigns each of your schemas an _id field by default if one is not passed into the Schema
1515
- * constructor. The type assigned is an ObjectId to coincide with MongoDB's default behavior. If you
1516
- * don't want an _id added to your schema at all, you may disable it using this option.
1517
- */
1518
- _id?: boolean;
1519
- /**
1520
- * Mongoose will, by default, "minimize" schemas by removing empty objects. This behavior can be
1521
- * overridden by setting minimize option to false. It will then store empty objects.
1522
- */
1523
- minimize?: boolean;
1524
- /**
1525
- * Optimistic concurrency is a strategy to ensure the document you're updating didn't change between when you
1526
- * loaded it using find() or findOne(), and when you update it using save(). Set to `true` to enable
1527
- * optimistic concurrency.
1528
- */
1529
- optimisticConcurrency?: boolean;
1530
- /**
1531
- * If `plugin()` called with tags, Mongoose will only apply plugins to schemas that have
1532
- * a matching tag in `pluginTags`
1533
- */
1534
- pluginTags?: string[];
1535
- /**
1536
- * Allows setting query#read options at the schema level, providing us a way to apply default ReadPreferences
1537
- * to all queries derived from a model.
1538
- */
1539
- read?: string;
1540
- /** Allows setting write concern at the schema level. */
1541
- writeConcern?: WriteConcern;
1542
- /** defaults to true. */
1543
- safe?: boolean | { w?: number | string; wtimeout?: number; j?: boolean };
1544
- /**
1545
- * The shardKey option is used when we have a sharded MongoDB architecture. Each sharded collection is
1546
- * given a shard key which must be present in all insert/update operations. We just need to set this
1547
- * schema option to the same shard key and we'll be all set.
1548
- */
1549
- shardKey?: Record<string, unknown>;
1550
- /**
1551
- * The strict option, (enabled by default), ensures that values passed to our model constructor that were not
1552
- * specified in our schema do not get saved to the db.
1553
- */
1554
- strict?: boolean | 'throw';
1555
- /**
1556
- * equal to `strict` by default, may be `false`, `true`, or `'throw'`. Sets the default
1557
- * [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
1558
- */
1559
- strictQuery?: boolean | 'throw';
1560
- /** Exactly the same as the toObject option but only applies when the document's toJSON method is called. */
1561
- toJSON?: ToObjectOptions;
1562
- /**
1563
- * Documents have a toObject method which converts the mongoose document into a plain JavaScript object.
1564
- * This method accepts a few options. Instead of applying these options on a per-document basis, we may
1565
- * declare the options at the schema level and have them applied to all of the schema's documents by
1566
- * default.
1567
- */
1568
- toObject?: ToObjectOptions;
1569
- /**
1570
- * By default, if you have an object with key 'type' in your schema, mongoose will interpret it as a
1571
- * type declaration. However, for applications like geoJSON, the 'type' property is important. If you want to
1572
- * control which key mongoose uses to find type declarations, set the 'typeKey' schema option.
1573
- */
1574
- typeKey?: string;
1575
-
1576
- /**
1577
- * By default, documents are automatically validated before they are saved to the database. This is to
1578
- * prevent saving an invalid document. If you want to handle validation manually, and be able to save
1579
- * objects which don't pass validation, you can set validateBeforeSave to false.
1580
- */
1581
- validateBeforeSave?: boolean;
1582
- /**
1583
- * The versionKey is a property set on each document when first created by Mongoose. This keys value
1584
- * contains the internal revision of the document. The versionKey option is a string that represents
1585
- * the path to use for versioning. The default is '__v'.
1586
- */
1587
- versionKey?: string | boolean;
1588
- /**
1589
- * By default, Mongoose will automatically select() any populated paths for you, unless you explicitly exclude them.
1590
- */
1591
- selectPopulatedPaths?: boolean;
1592
- /**
1593
- * skipVersioning allows excluding paths from versioning (i.e., the internal revision will not be
1594
- * incremented even if these paths are updated). DO NOT do this unless you know what you're doing.
1595
- * For subdocuments, include this on the parent document using the fully qualified path.
1596
- */
1597
- skipVersioning?: any;
1598
- /**
1599
- * Validation errors in a single nested schema are reported
1600
- * both on the child and on the parent schema.
1601
- * Set storeSubdocValidationError to false on the child schema
1602
- * to make Mongoose only report the parent error.
1603
- */
1604
- storeSubdocValidationError?: boolean;
1605
- /**
1606
- * The timestamps option tells mongoose to assign createdAt and updatedAt fields to your schema. The type
1607
- * assigned is Date. By default, the names of the fields are createdAt and updatedAt. Customize the
1608
- * field names by setting timestamps.createdAt and timestamps.updatedAt.
1609
- */
1610
- timestamps?: boolean | SchemaTimestampsConfig;
1611
-
1612
- /**
1613
- * Using `save`, `isNew`, and other Mongoose reserved names as schema path names now triggers a warning, not an error.
1614
- * You can suppress the warning by setting { supressReservedKeysWarning: true } schema options. Keep in mind that this
1615
- * can break plugins that rely on these reserved names.
1616
- */
1617
- supressReservedKeysWarning?: boolean
1618
- }
1619
-
1620
- interface SchemaTimestampsConfig {
1621
- createdAt?: boolean | string;
1622
- updatedAt?: boolean | string;
1623
- currentTime?: () => (NativeDate | number);
1624
- }
1625
-
1626
1040
  type Unpacked<T> = T extends (infer U)[] ?
1627
1041
  U :
1628
1042
  T extends ReadonlyArray<infer U> ? U : T;
1629
1043
 
1630
1044
  type AnyArray<T> = T[] | ReadonlyArray<T>;
1045
+ type SchemaValidator<T> = RegExp | [RegExp, string] | Function | [Function, string] | ValidateOpts<T> | ValidateOpts<T>[];
1631
1046
 
1632
1047
  export class SchemaTypeOptions<T> {
1633
1048
  type?:
@@ -1650,7 +1065,7 @@ declare module 'mongoose' {
1650
1065
  alias?: string;
1651
1066
 
1652
1067
  /** Function or object describing how to validate this schematype. See [validation docs](https://mongoosejs.com/docs/validation.html). */
1653
- validate?: RegExp | [RegExp, string] | Function | [Function, string] | ValidateOpts<T> | ValidateOpts<T>[];
1068
+ validate?: SchemaValidator<T> | AnyArray<SchemaValidator<T>>;
1654
1069
 
1655
1070
  /** Allows overriding casting logic for this individual path. If a string, the given string overwrites Mongoose's default cast error message. */
1656
1071
  cast?: string;
@@ -1846,15 +1261,15 @@ declare module 'mongoose' {
1846
1261
 
1847
1262
  type InferId<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
1848
1263
 
1849
- interface VirtualTypeOptions {
1264
+ interface VirtualTypeOptions<HydratedDocType = Document> {
1850
1265
  /** If `ref` is not nullish, this becomes a populated virtual. */
1851
1266
  ref?: string | Function;
1852
1267
 
1853
1268
  /** The local field to populate on if this is a populated virtual. */
1854
- localField?: string | Function;
1269
+ localField?: string | ((this: HydratedDocType, doc: HydratedDocType) => string);
1855
1270
 
1856
1271
  /** The foreign field to populate on if this is a populated virtual. */
1857
- foreignField?: string | Function;
1272
+ foreignField?: string | ((this: HydratedDocType, doc: HydratedDocType) => string);
1858
1273
 
1859
1274
  /**
1860
1275
  * By default, a populated virtual is an array. If you set `justOne`,
@@ -2161,8 +1576,11 @@ declare module 'mongoose' {
2161
1576
 
2162
1577
  type QueryWithHelpers<ResultType, DocType, THelpers = {}, RawDocType = DocType> = Query<ResultType, DocType, THelpers, RawDocType> & THelpers;
2163
1578
 
2164
- type UnpackedIntersection<T, U> = T extends (infer V)[] ? (V & U)[] : T & U;
2165
- type UnpackedIntersectionWithNull<T, U> = T extends null ? UnpackedIntersection<T, U> | null : UnpackedIntersection<T, U>;
1579
+ type UnpackedIntersection<T, U> = T extends (infer A)[]
1580
+ ? (Omit<A, keyof U> & U)[]
1581
+ : keyof U extends never
1582
+ ? T
1583
+ : Omit<T, keyof U> & U;
2166
1584
 
2167
1585
  type ProjectionFields<DocType> = {[Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any} & Record<string, any>;
2168
1586
 
@@ -2242,7 +1660,7 @@ declare module 'mongoose' {
2242
1660
  * Returns a wrapper around a [mongodb driver cursor](http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html).
2243
1661
  * A QueryCursor exposes a Streams3 interface, as well as a `.next()` function.
2244
1662
  */
2245
- cursor(options?: any): QueryCursor<DocType>;
1663
+ cursor(options?: QueryOptions): Cursor<DocType, QueryOptions>;
2246
1664
 
2247
1665
  /**
2248
1666
  * Declare and/or execute this query as a `deleteMany()` operation. Works like
@@ -2263,7 +1681,7 @@ declare module 'mongoose' {
2263
1681
  deleteOne(callback: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
2264
1682
 
2265
1683
  /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
2266
- distinct(field: string, filter?: FilterQuery<DocType>, callback?: Callback<number>): QueryWithHelpers<Array<any>, DocType, THelpers, RawDocType>;
1684
+ distinct<ReturnType = any>(field: string, filter?: FilterQuery<DocType>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, DocType, THelpers, RawDocType>;
2267
1685
 
2268
1686
  /** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */
2269
1687
  elemMatch(val: Function | any): this;
@@ -2463,8 +1881,8 @@ declare module 'mongoose' {
2463
1881
  polygon(path: string, ...coordinatePairs: number[][]): this;
2464
1882
 
2465
1883
  /** Specifies paths which should be populated with other documents. */
2466
- populate<Paths = {}>(path: string | any, select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersectionWithNull<ResultType, Paths>, DocType, THelpers, RawDocType>;
2467
- populate<Paths = {}>(options: PopulateOptions | Array<PopulateOptions>): QueryWithHelpers<UnpackedIntersectionWithNull<ResultType, Paths>, DocType, THelpers, RawDocType>;
1884
+ populate<Paths = {}>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType>;
1885
+ populate<Paths = {}>(options: PopulateOptions | (PopulateOptions | string)[]): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType>;
2468
1886
 
2469
1887
  /** Get/set the current projection (AKA fields). Pass `null` to remove the current projection. */
2470
1888
  projection(): ProjectionFields<DocType> | null;
@@ -2676,13 +2094,20 @@ declare module 'mongoose' {
2676
2094
  } &
2677
2095
  RootQuerySelector<T>;
2678
2096
 
2097
+ /**
2098
+ * Filter query to select the documents that match the query
2099
+ * @example
2100
+ * ```js
2101
+ * { age: { $gte: 30 } }
2102
+ * ```
2103
+ */
2679
2104
  export type FilterQuery<T> = _FilterQuery<T>;
2680
2105
 
2681
2106
  type AddToSetOperators<Type> = {
2682
2107
  $each: Type;
2683
2108
  };
2684
2109
 
2685
- type SortValues = -1 | 1 | 'asc' | 'desc';
2110
+ type SortValues = -1 | 1 | 'asc' | 'ascending' | 'desc' | 'descending';
2686
2111
 
2687
2112
  type ArrayOperator<Type> = {
2688
2113
  $each: Type;
@@ -2733,6 +2158,13 @@ declare module 'mongoose' {
2733
2158
  [K in keyof T]?: __UpdateDefProperty<T[K]>;
2734
2159
  };
2735
2160
 
2161
+ /**
2162
+ * Update query command to perform on the document
2163
+ * @example
2164
+ * ```js
2165
+ * { age: 30 }
2166
+ * ```
2167
+ */
2736
2168
  export type UpdateQuery<T> = _UpdateQuery<_UpdateQueryDef<T>> & AnyObject;
2737
2169
 
2738
2170
  export type DocumentDefinition<T> = {
@@ -2775,6 +2207,12 @@ declare module 'mongoose' {
2775
2207
  T;
2776
2208
 
2777
2209
  export type SchemaDefinitionType<T> = T extends Document ? Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>> : T;
2210
+
2211
+ /**
2212
+ * Documents returned from queries with the lean option enabled.
2213
+ * Plain old JavaScript object documents (POJO).
2214
+ * @see https://mongoosejs.com/docs/tutorials/lean.html
2215
+ */
2778
2216
  export type LeanDocument<T> = Omit<_LeanDocument<T>, Exclude<keyof Document, '_id' | 'id' | '__v'> | '$isSingleNested'>;
2779
2217
 
2780
2218
  export type LeanDocumentOrArray<T> = 0 extends (1 & T) ? T :
@@ -2787,49 +2225,6 @@ declare module 'mongoose' {
2787
2225
  T extends Document ? RawDocType :
2788
2226
  T;
2789
2227
 
2790
- class QueryCursor<DocType> extends stream.Readable {
2791
- [Symbol.asyncIterator](): AsyncIterableIterator<DocType>;
2792
-
2793
- /**
2794
- * Adds a [cursor flag](http://mongodb.github.io/node-mongodb-native/2.2/api/Cursor.html#addCursorFlag).
2795
- * Useful for setting the `noCursorTimeout` and `tailable` flags.
2796
- */
2797
- addCursorFlag(flag: string, value: boolean): this;
2798
-
2799
- /**
2800
- * Marks this cursor as closed. Will stop streaming and subsequent calls to
2801
- * `next()` will error.
2802
- */
2803
- close(): Promise<void>;
2804
- close(callback: CallbackWithoutResult): void;
2805
-
2806
- /**
2807
- * Execute `fn` for every document(s) in the cursor. If batchSize is provided
2808
- * `fn` will be executed for each batch of documents. If `fn` returns a promise,
2809
- * will wait for the promise to resolve before iterating on to the next one.
2810
- * Returns a promise that resolves when done.
2811
- */
2812
- eachAsync(fn: (doc: DocType) => any, options?: { parallel?: number }): Promise<void>;
2813
- eachAsync(fn: (doc: DocType[]) => any, options: { parallel?: number, batchSize: number }): Promise<void>;
2814
- eachAsync(fn: (doc: DocType) => any, options?: { parallel?: number, batchSize?: number }, cb?: CallbackWithoutResult): void;
2815
- eachAsync(fn: (doc: DocType[]) => any, options: { parallel?: number, batchSize: number }, cb?: CallbackWithoutResult): void;
2816
-
2817
- /**
2818
- * Registers a transform function which subsequently maps documents retrieved
2819
- * via the streams interface or `.next()`
2820
- */
2821
- map<ResultType>(fn: (res: DocType) => ResultType): QueryCursor<ResultType>;
2822
-
2823
- /**
2824
- * Get the next document from this cursor. Will return `null` when there are
2825
- * no documents left.
2826
- */
2827
- next(): Promise<DocType>;
2828
- next(callback: Callback<DocType | null>): void;
2829
-
2830
- options: any;
2831
- }
2832
-
2833
2228
  class Aggregate<R> {
2834
2229
  /**
2835
2230
  * Returns an asyncIterator for use with [`for/await/of` loops](https://thecodebarbarian.com/getting-started-with-async-iterators-in-node-js
@@ -2871,7 +2266,7 @@ declare module 'mongoose' {
2871
2266
  /**
2872
2267
  * Sets the cursor option for the aggregation query (ignored for < 2.6.0).
2873
2268
  */
2874
- cursor(options?: Record<string, unknown>): AggregationCursor;
2269
+ cursor<DocType = any>(options?: Record<string, unknown>): Cursor<DocType>;
2875
2270
 
2876
2271
  /** Executes the aggregate pipeline on the currently bound Model. */
2877
2272
  exec(callback?: Callback<R>): Promise<R>;
@@ -2959,7 +2354,7 @@ declare module 'mongoose' {
2959
2354
  skip(num: number): this;
2960
2355
 
2961
2356
  /** Appends a new $sort operator to this aggregate pipeline. */
2962
- sort(arg: PipelineStage.Sort['$sort']): this;
2357
+ sort(arg: string | Record<string, SortValues> | PipelineStage.Sort['$sort']): this;
2963
2358
 
2964
2359
  /** Provides promise for aggregate. */
2965
2360
  then: Promise<R>['then'];
@@ -2977,43 +2372,6 @@ declare module 'mongoose' {
2977
2372
  unwind(...args: PipelineStage.Unwind['$unwind'][]): this;
2978
2373
  }
2979
2374
 
2980
- class AggregationCursor extends stream.Readable {
2981
- /**
2982
- * Adds a [cursor flag](http://mongodb.github.io/node-mongodb-native/2.2/api/Cursor.html#addCursorFlag).
2983
- * Useful for setting the `noCursorTimeout` and `tailable` flags.
2984
- */
2985
- addCursorFlag(flag: string, value: boolean): this;
2986
-
2987
- /**
2988
- * Marks this cursor as closed. Will stop streaming and subsequent calls to
2989
- * `next()` will error.
2990
- */
2991
- close(): Promise<void>;
2992
- close(callback: CallbackWithoutResult): void;
2993
-
2994
- /**
2995
- * Execute `fn` for every document(s) in the cursor. If batchSize is provided
2996
- * `fn` will be executed for each batch of documents. If `fn` returns a promise,
2997
- * will wait for the promise to resolve before iterating on to the next one.
2998
- * Returns a promise that resolves when done.
2999
- */
3000
- eachAsync(fn: (doc: any) => any, options?: { parallel?: number, batchSize?: number }): Promise<void>;
3001
- eachAsync(fn: (doc: any) => any, options?: { parallel?: number, batchSize?: number }, cb?: CallbackWithoutResult): void;
3002
-
3003
- /**
3004
- * Registers a transform function which subsequently maps documents retrieved
3005
- * via the streams interface or `.next()`
3006
- */
3007
- map(fn: (res: any) => any): this;
3008
-
3009
- /**
3010
- * Get the next document from this cursor. Will return `null` when there are
3011
- * no documents left.
3012
- */
3013
- next(): Promise<any>;
3014
- next(callback: Callback): void;
3015
- }
3016
-
3017
2375
  class SchemaType {
3018
2376
  /** SchemaType constructor */
3019
2377
  constructor(path: string, options?: AnyObject, instance?: string);
@@ -3111,6 +2469,7 @@ declare module 'mongoose' {
3111
2469
  type Callback<T = any> = (error: CallbackError, result: T) => void;
3112
2470
 
3113
2471
  type CallbackWithoutResult = (error: CallbackError) => void;
2472
+ type CallbackWithoutResultAndOptionalError = (error?: CallbackError) => void;
3114
2473
 
3115
2474
  /* for ts-mongoose */
3116
2475
  class mquery {}