mongoose 6.2.1 → 6.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/.eslintrc.json +5 -1
  2. package/.lgtm.yml +3 -0
  3. package/CHANGELOG.md +54 -0
  4. package/dist/browser.umd.js +156 -152
  5. package/index.js +5 -1
  6. package/lib/aggregate.js +22 -27
  7. package/lib/browserDocument.js +1 -1
  8. package/lib/cast/number.js +2 -3
  9. package/lib/cast.js +7 -4
  10. package/lib/connection.js +43 -21
  11. package/lib/cursor/AggregationCursor.js +12 -7
  12. package/lib/cursor/QueryCursor.js +11 -6
  13. package/lib/document.js +58 -72
  14. package/lib/drivers/node-mongodb-native/collection.js +12 -4
  15. package/lib/drivers/node-mongodb-native/connection.js +11 -0
  16. package/lib/error/cast.js +3 -2
  17. package/lib/helpers/clone.js +11 -2
  18. package/lib/helpers/cursor/eachAsync.js +18 -15
  19. package/lib/helpers/document/cleanModifiedSubpaths.js +1 -0
  20. package/lib/helpers/document/compile.js +7 -4
  21. package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +14 -0
  22. package/lib/helpers/indexes/getRelatedIndexes.js +59 -0
  23. package/lib/helpers/isAsyncFunction.js +6 -7
  24. package/lib/helpers/populate/assignVals.js +4 -0
  25. package/lib/helpers/printJestWarning.js +2 -2
  26. package/lib/helpers/projection/applyProjection.js +77 -0
  27. package/lib/helpers/projection/hasIncludedChildren.js +36 -0
  28. package/lib/helpers/projection/isExclusive.js +5 -2
  29. package/lib/helpers/projection/isInclusive.js +5 -1
  30. package/lib/helpers/query/cast$expr.js +14 -19
  31. package/lib/helpers/query/hasDollarKeys.js +7 -3
  32. package/lib/helpers/query/isOperator.js +5 -2
  33. package/lib/helpers/schema/getIndexes.js +6 -2
  34. package/lib/index.js +14 -17
  35. package/lib/internal.js +9 -1
  36. package/lib/model.js +159 -153
  37. package/lib/options/SchemaTypeOptions.js +1 -1
  38. package/lib/plugins/trackTransaction.js +1 -1
  39. package/lib/query.js +159 -147
  40. package/lib/queryhelpers.js +8 -28
  41. package/lib/schema/SubdocumentPath.js +5 -4
  42. package/lib/schema/array.js +13 -6
  43. package/lib/schema/buffer.js +1 -1
  44. package/lib/schema/date.js +1 -1
  45. package/lib/schema/decimal128.js +1 -1
  46. package/lib/schema/documentarray.js +9 -7
  47. package/lib/schema/number.js +1 -1
  48. package/lib/schema/objectid.js +1 -1
  49. package/lib/schema/string.js +4 -4
  50. package/lib/schema.js +12 -8
  51. package/lib/schematype.js +12 -14
  52. package/lib/types/ArraySubdocument.js +1 -1
  53. package/lib/types/DocumentArray/index.js +1 -1
  54. package/lib/types/array/index.js +2 -2
  55. package/lib/types/array/methods/index.js +10 -11
  56. package/lib/types/buffer.js +3 -3
  57. package/lib/types/map.js +3 -4
  58. package/lib/utils.js +9 -3
  59. package/package.json +17 -21
  60. package/tsconfig.json +0 -2
  61. package/types/Connection.d.ts +212 -0
  62. package/types/Error.d.ts +129 -0
  63. package/types/PipelineStage.d.ts +272 -0
  64. package/types/index.d.ts +61 -602
  65. package/lib/types/array/ArrayWrapper.js +0 -981
package/types/index.d.ts CHANGED
@@ -1,16 +1,13 @@
1
+ /// <reference path="./Error.d.ts" />
2
+ /// <reference path="./PipelineStage.d.ts" />
3
+ /// <reference path="./Connection.d.ts" />
4
+
5
+ import events = require('events');
6
+ import mongodb = require('mongodb');
7
+ import mongoose = require('mongoose');
8
+ import stream = require('stream');
9
+
1
10
  declare module 'mongoose' {
2
- import events = require('events');
3
- import mongodb = require('mongodb');
4
- import mongoose = require('mongoose');
5
- import stream = require('stream');
6
-
7
- export enum ConnectionStates {
8
- disconnected = 0,
9
- connected = 1,
10
- connecting = 2,
11
- disconnecting = 3,
12
- uninitialized = 99,
13
- }
14
11
 
15
12
  class NativeDate extends global.Date {}
16
13
 
@@ -60,9 +57,6 @@ declare module 'mongoose' {
60
57
  /** The various Mongoose SchemaTypes. */
61
58
  export const SchemaTypes: typeof Schema.Types;
62
59
 
63
- /** Expose connection states for user-land */
64
- export const STATES: typeof ConnectionStates;
65
-
66
60
  /** Opens Mongoose's default connection to MongoDB, see [connections docs](https://mongoosejs.com/docs/connections.html) */
67
61
  export function connect(uri: string, options: ConnectOptions, callback: CallbackWithoutResult): void;
68
62
  export function connect(uri: string, callback: CallbackWithoutResult): void;
@@ -96,10 +90,11 @@ declare module 'mongoose' {
96
90
 
97
91
  /** An array containing all models associated with this Mongoose instance. */
98
92
  export const models: Models;
93
+
99
94
  /** Creates a Connection instance. */
95
+ export function createConnection(uri: string, options: ConnectOptions, callback: Callback<Connection>): void;
100
96
  export function createConnection(uri: string, options?: ConnectOptions): Connection;
101
97
  export function createConnection(): Connection;
102
- export function createConnection(uri: string, options: ConnectOptions, callback: Callback<Connection>): void;
103
98
 
104
99
  /**
105
100
  * Removes the model named `name` from the default connection, if it exists.
@@ -114,7 +109,7 @@ declare module 'mongoose' {
114
109
  /** Gets mongoose options */
115
110
  export function get<K extends keyof MongooseOptions>(key: K): MongooseOptions[K];
116
111
 
117
- /*! ignore */
112
+ /* ! ignore */
118
113
  type CompileModelOptions = { overwriteModels?: boolean, connection?: Connection };
119
114
 
120
115
  /**
@@ -284,190 +279,6 @@ declare module 'mongoose' {
284
279
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
285
280
  interface ClientSession extends mongodb.ClientSession { }
286
281
 
287
- interface ConnectOptions extends mongodb.MongoClientOptions {
288
- /** Set to false to [disable buffering](http://mongoosejs.com/docs/faq.html#callback_never_executes) on all models associated with this connection. */
289
- bufferCommands?: boolean;
290
- /** The name of the database you want to use. If not provided, Mongoose uses the database name from connection string. */
291
- dbName?: string;
292
- /** username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility. */
293
- user?: string;
294
- /** password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility. */
295
- pass?: string;
296
- /** Set to false to disable automatic index creation for all models associated with this connection. */
297
- autoIndex?: boolean;
298
- /** Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection. */
299
- autoCreate?: boolean;
300
- }
301
-
302
- class Connection extends events.EventEmitter {
303
- /** Returns a promise that resolves when this connection successfully connects to MongoDB */
304
- asPromise(): Promise<this>;
305
-
306
- /** Closes the connection */
307
- close(callback: CallbackWithoutResult): void;
308
- close(force: boolean, callback: CallbackWithoutResult): void;
309
- close(force?: boolean): Promise<void>;
310
-
311
- /** Retrieves a collection, creating it if not cached. */
312
- collection<T = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Collection<T>;
313
-
314
- /** A hash of the collections associated with this connection */
315
- collections: { [index: string]: Collection };
316
-
317
- /** A hash of the global options that are associated with this connection */
318
- config: any;
319
-
320
- /** The mongodb.Db instance, set when the connection is opened */
321
- db: mongodb.Db;
322
-
323
- /**
324
- * Helper for `createCollection()`. Will explicitly create the given collection
325
- * with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
326
- * and [views](https://docs.mongodb.com/manual/core/views/) from mongoose.
327
- */
328
- createCollection<T = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
329
- createCollection<T = AnyObject>(name: string, cb: Callback<mongodb.Collection<T>>): void;
330
- createCollection<T = AnyObject>(name: string, options: mongodb.CreateCollectionOptions, cb?: Callback<mongodb.Collection<T>>): Promise<mongodb.Collection<T>>;
331
-
332
- /**
333
- * Removes the model named `name` from this connection, if it exists. You can
334
- * use this function to clean up any models you created in your tests to
335
- * prevent OverwriteModelErrors.
336
- */
337
- deleteModel(name: string): this;
338
-
339
- /**
340
- * Helper for `dropCollection()`. Will delete the given collection, including
341
- * all documents and indexes.
342
- */
343
- dropCollection(collection: string): Promise<void>;
344
- dropCollection(collection: string, cb: CallbackWithoutResult): void;
345
-
346
- /**
347
- * Helper for `dropDatabase()`. Deletes the given database, including all
348
- * collections, documents, and indexes.
349
- */
350
- dropDatabase(): Promise<void>;
351
- dropDatabase(cb: CallbackWithoutResult): void;
352
-
353
- /** Gets the value of the option `key`. Equivalent to `conn.options[key]` */
354
- get(key: string): any;
355
-
356
- /**
357
- * Returns the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
358
- * that this connection uses to talk to MongoDB.
359
- */
360
- getClient(): mongodb.MongoClient;
361
-
362
- /**
363
- * The host name portion of the URI. If multiple hosts, such as a replica set,
364
- * this will contain the first host name in the URI
365
- */
366
- host: string;
367
-
368
- /**
369
- * A number identifier for this connection. Used for debugging when
370
- * you have [multiple connections](/docs/connections.html#multiple_connections).
371
- */
372
- id: number;
373
-
374
- /**
375
- * A [POJO](https://masteringjs.io/tutorials/fundamentals/pojo) containing
376
- * a map from model names to models. Contains all models that have been
377
- * added to this connection using [`Connection#model()`](/docs/api/connection.html#connection_Connection-model).
378
- */
379
- models: { [index: string]: Model<any> };
380
-
381
- /** Defines or retrieves a model. */
382
- model<T>(name: string, schema?: Schema<any>, collection?: string, options?: CompileModelOptions): Model<T>;
383
- model<T, U, TQueryHelpers = {}>(
384
- name: string,
385
- schema?: Schema<T, U, TQueryHelpers>,
386
- collection?: string,
387
- options?: CompileModelOptions
388
- ): U;
389
-
390
- /** Returns an array of model names created on this connection. */
391
- modelNames(): Array<string>;
392
-
393
- /** The name of the database this connection points to. */
394
- name: string;
395
-
396
- /** Opens the connection with a URI using `MongoClient.connect()`. */
397
- openUri(uri: string, options?: ConnectOptions): Promise<Connection>;
398
- openUri(uri: string, callback: (err: CallbackError, conn?: Connection) => void): Connection;
399
- openUri(uri: string, options: ConnectOptions, callback: (err: CallbackError, conn?: Connection) => void): Connection;
400
-
401
- /** The password specified in the URI */
402
- pass: string;
403
-
404
- /**
405
- * The port portion of the URI. If multiple hosts, such as a replica set,
406
- * this will contain the port from the first host name in the URI.
407
- */
408
- port: number;
409
-
410
- /** Declares a plugin executed on all schemas you pass to `conn.model()` */
411
- plugin(fn: (schema: Schema, opts?: any) => void, opts?: any): Connection;
412
-
413
- /** The plugins that will be applied to all models created on this connection. */
414
- plugins: Array<any>;
415
-
416
- /**
417
- * Connection ready state
418
- *
419
- * - 0 = disconnected
420
- * - 1 = connected
421
- * - 2 = connecting
422
- * - 3 = disconnecting
423
- */
424
- readyState: number;
425
-
426
- /** Sets the value of the option `key`. Equivalent to `conn.options[key] = val` */
427
- set(key: string, value: any): any;
428
-
429
- /**
430
- * Set the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
431
- * that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to
432
- * reuse it.
433
- */
434
- setClient(client: mongodb.MongoClient): this;
435
-
436
- /**
437
- * _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
438
- * for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
439
- * and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
440
- */
441
- startSession(options?: mongodb.ClientSessionOptions): Promise<mongodb.ClientSession>;
442
- startSession(options: mongodb.ClientSessionOptions, cb: Callback<mongodb.ClientSession>): void;
443
-
444
- /**
445
- * Makes the indexes in MongoDB match the indexes defined in every model's
446
- * schema. This function will drop any indexes that are not defined in
447
- * the model's schema except the `_id` index, and build any indexes that
448
- * are in your schema but not in MongoDB.
449
- */
450
- syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
451
- syncIndexes(options: SyncIndexesOptions | null, callback: Callback<ConnectionSyncIndexesResult>): void;
452
-
453
- /**
454
- * _Requires MongoDB >= 3.6.0._ Executes the wrapped async function
455
- * in a transaction. Mongoose will commit the transaction if the
456
- * async function executes successfully and attempt to retry if
457
- * there was a retryable error.
458
- */
459
- transaction(fn: (session: mongodb.ClientSession) => Promise<any>): Promise<any>;
460
-
461
- /** Switches to a different database using the same connection pool. */
462
- useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;
463
-
464
- /** The username specified in the URI */
465
- user: string;
466
-
467
- /** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model.watch). */
468
- watch<ResultType = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
469
- }
470
-
471
282
  /*
472
283
  * section collection.js
473
284
  * http://mongoosejs.com/docs/api.html#collection-js
@@ -910,12 +721,12 @@ declare module 'mongoose' {
910
721
  init(callback?: CallbackWithoutResult): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
911
722
 
912
723
  /** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
913
- insertMany(docs: Array<AnyKeys<T> | AnyObject>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
724
+ insertMany(docs: Array<AnyKeys<T> | AnyObject>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult<T>>;
914
725
  insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
915
- insertMany(doc: AnyKeys<T> | AnyObject, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
726
+ insertMany(doc: AnyKeys<T> | AnyObject, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult<T>>;
916
727
  insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
917
- insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[] | InsertManyResult>): void;
918
- insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>> | InsertManyResult>): void;
728
+ insertMany(doc: AnyKeys<T> | AnyObject, options?: InsertManyOptions, callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[] | InsertManyResult<T>>): void;
729
+ insertMany(docs: Array<AnyKeys<T> | AnyObject>, options?: InsertManyOptions, callback?: Callback<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>> | InsertManyResult<T>>): void;
919
730
 
920
731
  /**
921
732
  * Lists the indexes currently defined in MongoDB. This may or may not be
@@ -977,7 +788,7 @@ declare module 'mongoose' {
977
788
  translateAliases(raw: any): any;
978
789
 
979
790
  /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
980
- distinct(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<any>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
791
+ distinct<ReturnType = any>(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
981
792
 
982
793
  /** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
983
794
  estimatedDocumentCount(options?: QueryOptions, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
@@ -1166,9 +977,13 @@ declare module 'mongoose' {
1166
977
  populate?: string | string[] | PopulateOptions | PopulateOptions[];
1167
978
  }
1168
979
 
1169
- interface InsertManyResult extends mongodb.InsertManyResult {
1170
- mongoose?: { validationErrors?: Array<Error.CastError | Error.ValidatorError> }
1171
- }
980
+ type InferIdType<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
981
+ type InsertManyResult<T> = mongodb.InsertManyResult<T> & {
982
+ insertedIds: {
983
+ [key: number]: InferIdType<T>;
984
+ };
985
+ mongoose?: { validationErrors?: Array<Error.CastError | Error.ValidatorError> };
986
+ };
1172
987
 
1173
988
  interface MapReduceOptions<T, Key, Val> {
1174
989
  map: Function | string;
@@ -1301,6 +1116,9 @@ declare module 'mongoose' {
1301
1116
  /** Returns a copy of this schema */
1302
1117
  clone<T = this>(): T;
1303
1118
 
1119
+ /** Returns a new schema that has the picked `paths` from this schema. */
1120
+ pick<T = this>(paths: string[], options?: SchemaOptions): T;
1121
+
1304
1122
  /** Object containing discriminators defined on this schema */
1305
1123
  discriminators?: { [name: string]: Schema };
1306
1124
 
@@ -1374,7 +1192,9 @@ declare module 'mongoose' {
1374
1192
 
1375
1193
  /** Defines a pre hook for the model. */
1376
1194
  pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', fn: PreSaveMiddlewareFunction<T>): this;
1195
+ pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', options: SchemaPreOptions, fn: PreSaveMiddlewareFunction<T>): this;
1377
1196
  pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PreMiddlewareFunction<T>): this;
1197
+ pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
1378
1198
  pre<T extends Query<any, any>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
1379
1199
  pre<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PreMiddlewareFunction<T>): this;
1380
1200
  pre<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
@@ -1598,6 +1418,13 @@ declare module 'mongoose' {
1598
1418
  * field names by setting timestamps.createdAt and timestamps.updatedAt.
1599
1419
  */
1600
1420
  timestamps?: boolean | SchemaTimestampsConfig;
1421
+
1422
+ /**
1423
+ * Using `save`, `isNew`, and other Mongoose reserved names as schema path names now triggers a warning, not an error.
1424
+ * You can suppress the warning by setting { supressReservedKeysWarning: true } schema options. Keep in mind that this
1425
+ * can break plugins that rely on these reserved names.
1426
+ */
1427
+ supressReservedKeysWarning?: boolean
1601
1428
  }
1602
1429
 
1603
1430
  interface SchemaTimestampsConfig {
@@ -1611,6 +1438,7 @@ declare module 'mongoose' {
1611
1438
  T extends ReadonlyArray<infer U> ? U : T;
1612
1439
 
1613
1440
  type AnyArray<T> = T[] | ReadonlyArray<T>;
1441
+ type SchemaValidator<T> = RegExp | [RegExp, string] | Function | [Function, string] | ValidateOpts<T> | ValidateOpts<T>[];
1614
1442
 
1615
1443
  export class SchemaTypeOptions<T> {
1616
1444
  type?:
@@ -1633,7 +1461,7 @@ declare module 'mongoose' {
1633
1461
  alias?: string;
1634
1462
 
1635
1463
  /** Function or object describing how to validate this schematype. See [validation docs](https://mongoosejs.com/docs/validation.html). */
1636
- validate?: RegExp | [RegExp, string] | Function | [Function, string] | ValidateOpts<T> | ValidateOpts<T>[];
1464
+ validate?: SchemaValidator<T> | AnyArray<SchemaValidator<T>>;
1637
1465
 
1638
1466
  /** Allows overriding casting logic for this individual path. If a string, the given string overwrites Mongoose's default cast error message. */
1639
1467
  cast?: string;
@@ -2246,7 +2074,7 @@ declare module 'mongoose' {
2246
2074
  deleteOne(callback: Callback): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
2247
2075
 
2248
2076
  /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
2249
- distinct(field: string, filter?: FilterQuery<DocType>, callback?: Callback<number>): QueryWithHelpers<Array<any>, DocType, THelpers, RawDocType>;
2077
+ distinct<ReturnType = any>(field: string, filter?: FilterQuery<DocType>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, DocType, THelpers, RawDocType>;
2250
2078
 
2251
2079
  /** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */
2252
2080
  elemMatch(val: Function | any): this;
@@ -2659,6 +2487,13 @@ declare module 'mongoose' {
2659
2487
  } &
2660
2488
  RootQuerySelector<T>;
2661
2489
 
2490
+ /**
2491
+ * Filter query to select the documents that match the query
2492
+ * @example
2493
+ * ```js
2494
+ * { age: { $gte: 30 } }
2495
+ * ```
2496
+ */
2662
2497
  export type FilterQuery<T> = _FilterQuery<T>;
2663
2498
 
2664
2499
  type AddToSetOperators<Type> = {
@@ -2716,6 +2551,13 @@ declare module 'mongoose' {
2716
2551
  [K in keyof T]?: __UpdateDefProperty<T[K]>;
2717
2552
  };
2718
2553
 
2554
+ /**
2555
+ * Update query command to perform on the document
2556
+ * @example
2557
+ * ```js
2558
+ * { age: 30 }
2559
+ * ```
2560
+ */
2719
2561
  export type UpdateQuery<T> = _UpdateQuery<_UpdateQueryDef<T>> & AnyObject;
2720
2562
 
2721
2563
  export type DocumentDefinition<T> = {
@@ -2758,6 +2600,12 @@ declare module 'mongoose' {
2758
2600
  T;
2759
2601
 
2760
2602
  export type SchemaDefinitionType<T> = T extends Document ? Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>> : T;
2603
+
2604
+ /**
2605
+ * Documents returned from queries with the lean option enabled.
2606
+ * Plain old JavaScript object documents (POJO).
2607
+ * @see https://mongoosejs.com/docs/tutorials/lean.html
2608
+ */
2761
2609
  export type LeanDocument<T> = Omit<_LeanDocument<T>, Exclude<keyof Document, '_id' | 'id' | '__v'> | '$isSingleNested'>;
2762
2610
 
2763
2611
  export type LeanDocumentOrArray<T> = 0 extends (1 & T) ? T :
@@ -2997,272 +2845,6 @@ declare module 'mongoose' {
2997
2845
  next(callback: Callback): void;
2998
2846
  }
2999
2847
 
3000
- /**
3001
- * [Stages reference](https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/#aggregation-pipeline-stages)
3002
- */
3003
- export type PipelineStage =
3004
- | PipelineStage.AddFields
3005
- | PipelineStage.Bucket
3006
- | PipelineStage.BucketAuto
3007
- | PipelineStage.CollStats
3008
- | PipelineStage.Count
3009
- | PipelineStage.Facet
3010
- | PipelineStage.GeoNear
3011
- | PipelineStage.GraphLookup
3012
- | PipelineStage.Group
3013
- | PipelineStage.IndexStats
3014
- | PipelineStage.Limit
3015
- | PipelineStage.ListSessions
3016
- | PipelineStage.Lookup
3017
- | PipelineStage.Match
3018
- | PipelineStage.Merge
3019
- | PipelineStage.Out
3020
- | PipelineStage.PlanCacheStats
3021
- | PipelineStage.Project
3022
- | PipelineStage.Redact
3023
- | PipelineStage.ReplaceRoot
3024
- | PipelineStage.ReplaceWith
3025
- | PipelineStage.Sample
3026
- | PipelineStage.Search
3027
- | PipelineStage.Set
3028
- | PipelineStage.SetWindowFields
3029
- | PipelineStage.Skip
3030
- | PipelineStage.Sort
3031
- | PipelineStage.SortByCount
3032
- | PipelineStage.UnionWith
3033
- | PipelineStage.Unset
3034
- | PipelineStage.Unwind
3035
-
3036
- export namespace PipelineStage {
3037
- export interface AddFields {
3038
- /** [`$addFields` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/addFields/) */
3039
- $addFields: Record<string, any>
3040
- }
3041
-
3042
- export interface Bucket {
3043
- /** [`$bucket` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/bucket/) */
3044
- $bucket: {
3045
- groupBy: any
3046
- boundaries: any[]
3047
- default?: any
3048
- output?: Record<string, { [op in AccumulatorOperator]?: any }>
3049
- }
3050
- }
3051
-
3052
- export interface BucketAuto {
3053
- /** [`$bucketAuto` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/) */
3054
- $bucketAuto: {
3055
- groupBy: any
3056
- buckets: number
3057
- output?: Record<string, { [op in AccumulatorOperator]?: any }>
3058
- granularity?: 'R5' | 'R10' | 'R20' | 'R40' | 'R80' | '1-2-5' | 'E6' | 'E12' | 'E24' | 'E48' | 'E96' | 'E192' | 'POWERSOF2'
3059
- }
3060
- }
3061
-
3062
- export interface CollStats {
3063
- /** [`$collStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/collStats/) */
3064
- $collStats: {
3065
- latencyStats?: { histograms?: boolean }
3066
- storageStats?: { scale?: number }
3067
- count?: {}
3068
- queryExecStats?: {}
3069
- }
3070
- }
3071
-
3072
- export interface Count {
3073
- /** [`$count` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/count/) */
3074
- $count: string
3075
- }
3076
-
3077
- export interface Facet {
3078
- /** [`$facet` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/facet/) */
3079
- $facet: Record<string, FacetPipelineStage[]>
3080
- }
3081
-
3082
- export type FacetPipelineStage = Exclude<PipelineStage, PipelineStage.CollStats | PipelineStage.Facet | PipelineStage.GeoNear | PipelineStage.IndexStats | PipelineStage.Out | PipelineStage.Merge | PipelineStage.PlanCacheStats>
3083
-
3084
- export interface GeoNear {
3085
- /** [`$geoNear` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/) */
3086
- $geoNear: {
3087
- near: { type: 'Point'; coordinates: [number, number] } | [number, number]
3088
- distanceField: string
3089
- distanceMultiplier?: number
3090
- includeLocs?: string
3091
- key?: string
3092
- maxDistance?: number
3093
- minDistance?: number
3094
- query?: AnyObject
3095
- spherical?: boolean
3096
- uniqueDocs?: boolean
3097
- }
3098
- }
3099
-
3100
- export interface GraphLookup {
3101
- /** [`$graphLookup` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/) */
3102
- $graphLookup: {
3103
- from: string
3104
- startWith: any
3105
- connectFromField: string
3106
- connectToField: string
3107
- as: string
3108
- maxDepth?: number
3109
- depthField?: string
3110
- restrictSearchWithMatch?: AnyObject
3111
- }
3112
- }
3113
-
3114
- export interface Group {
3115
- /** [`$group` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/group) */
3116
- $group: { _id: any } | { [key: string]: { [op in AccumulatorOperator]?: any } }
3117
- }
3118
-
3119
- export interface IndexStats {
3120
- /** [`$indexStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/) */
3121
- $indexStats: {}
3122
- }
3123
-
3124
- export interface Limit {
3125
- /** [`$limit` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/limit/) */
3126
- $limit: number
3127
- }
3128
-
3129
- export interface ListSessions {
3130
- /** [`$listSessions` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/listSessions/) */
3131
- $listSessions: { users?: { user: string; db: string }[] } | { allUsers?: true }
3132
- }
3133
-
3134
- export interface Lookup {
3135
- /** [`$lookup` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/) */
3136
- $lookup: {
3137
- from: string
3138
- as: string
3139
- localField?: string
3140
- foreignField?: string
3141
- let?: Record<string, any>
3142
- pipeline?: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out | PipelineStage.Search>[]
3143
- }
3144
- }
3145
-
3146
- export interface Match {
3147
- /** [`$match` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/match/) */
3148
- $match: AnyObject
3149
- }
3150
-
3151
- export interface Merge {
3152
- /** [`$merge` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/merge/) */
3153
- $merge: {
3154
- into: string | { db: string; coll: string }
3155
- on?: string | string[]
3156
- let?: Record<string, any>
3157
- whenMatched?: 'replace' | 'keepExisting' | 'merge' | 'fail' | Extract<PipelineStage, PipelineStage.AddFields | PipelineStage.Set | PipelineStage.Project | PipelineStage.Unset | PipelineStage.ReplaceRoot | PipelineStage.ReplaceWith>[]
3158
- whenNotMatched?: 'insert' | 'discard' | 'fail'
3159
- }
3160
- }
3161
-
3162
- export interface Out {
3163
- /** [`$out` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/out/) */
3164
- $out: string | { db: string; coll: string }
3165
- }
3166
-
3167
- export interface PlanCacheStats {
3168
- /** [`$planCacheStats` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/planCacheStats/) */
3169
- $planCacheStats: {}
3170
- }
3171
-
3172
- export interface Project {
3173
- /** [`$project` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/project/) */
3174
- $project: { [field: string]: any }
3175
- }
3176
-
3177
- export interface Redact {
3178
- /** [`$redact` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/redact/) */
3179
- $redact: any
3180
- }
3181
-
3182
- export interface ReplaceRoot {
3183
- /** [`$replaceRoot` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceRoot/) */
3184
- $replaceRoot: { newRoot: any }
3185
- }
3186
-
3187
- export interface ReplaceWith {
3188
- /** [`$replaceWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceWith/) */
3189
- $replaceWith: any
3190
- }
3191
-
3192
- export interface Sample {
3193
- /** [`$sample` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sample/) */
3194
- $sample: { size: number }
3195
- }
3196
-
3197
- export interface Search {
3198
- /** [`$search` reference](https://docs.atlas.mongodb.com/reference/atlas-search/query-syntax/) */
3199
- $search: {
3200
- [key: string]: any
3201
- index?: string
3202
- highlight?: { path: string; maxCharsToExamine?: number; maxNumPassages?: number }
3203
- }
3204
- }
3205
-
3206
- export interface Set {
3207
- /** [`$set` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/set/) */
3208
- $set: Record<string, any>
3209
- }
3210
-
3211
- export interface SetWindowFields {
3212
- /** [`$setWindowFields` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/setWindowFields/) */
3213
- $setWindowFields: {
3214
- partitionBy?: any
3215
- sortBy?: Record<string, 1 | -1>
3216
- output: Record<
3217
- string,
3218
- { [op in WindowOperator]?: any } & {
3219
- window?: {
3220
- documents?: [string | number, string | number]
3221
- range?: [string | number, string | number]
3222
- unit?: 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond'
3223
- }
3224
- }
3225
- >
3226
- }
3227
- }
3228
-
3229
- export interface Skip {
3230
- /** [`$skip` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/skip/) */
3231
- $skip: number
3232
- }
3233
-
3234
- export interface Sort {
3235
- /** [`$sort` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sort/) */
3236
- $sort: Record<string, 1 | -1 | { $meta: 'textScore' }>
3237
- }
3238
-
3239
- export interface SortByCount {
3240
- /** [`$sortByCount` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/sortByCount/) */
3241
- $sortByCount: any
3242
- }
3243
-
3244
- export interface UnionWith {
3245
- /** [`$unionWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unionWith/) */
3246
- $unionWith:
3247
- | string
3248
- | { coll: string; pipeline?: Exclude<PipelineStage, PipelineStage.Out | PipelineStage.Merge>[] }
3249
- }
3250
-
3251
- export interface Unset {
3252
- /** [`$unset` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unset/) */
3253
- $unset: string | string[]
3254
- }
3255
-
3256
- export interface Unwind {
3257
- /** [`$unwind` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/) */
3258
- $unwind: string | { path: string; includeArrayIndex?: string; preserveNullAndEmptyArrays?: boolean }
3259
- }
3260
-
3261
- type AccumulatorOperator = '$accumulator' | '$addToSet' | '$avg' | '$count' | '$first' | '$last' | '$max' | '$mergeObjects' | '$min' | '$push' | '$stdDevPop' | '$stdDevSamp' | '$sum'
3262
-
3263
- type WindowOperator = '$addToSet' | '$avg' | '$count' | '$covariancePop' | '$covarianceSamp' | '$derivative' | '$expMovingAvg' | '$integral' | '$max' | '$min' | '$push' | '$stdDevSamp' | '$stdDevPop' | '$sum' | '$first' | '$last' | '$shift' | '$denseRank' | '$documentNumber' | '$rank'
3264
- }
3265
-
3266
2848
  class SchemaType {
3267
2849
  /** SchemaType constructor */
3268
2850
  constructor(path: string, options?: AnyObject, instance?: string);
@@ -3361,131 +2943,8 @@ declare module 'mongoose' {
3361
2943
 
3362
2944
  type CallbackWithoutResult = (error: CallbackError) => void;
3363
2945
 
3364
- class NativeError extends global.Error { }
3365
- type CallbackError = NativeError | null;
3366
-
3367
- class Error extends global.Error {
3368
- constructor(msg: string);
3369
-
3370
- /** The type of error. "MongooseError" for generic errors. */
3371
- name: string;
3372
-
3373
- static messages: any;
3374
-
3375
- static Messages: any;
3376
- }
3377
-
3378
- namespace Error {
3379
- export class CastError extends Error {
3380
- name: 'CastError';
3381
- stringValue: string;
3382
- kind: string;
3383
- value: any;
3384
- path: string;
3385
- reason?: NativeError | null;
3386
- model?: any;
3387
-
3388
- constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
3389
- }
3390
- export class SyncIndexesError extends Error {
3391
- name: 'SyncIndexesError';
3392
- errors?: Record<string, mongodb.MongoServerError>;
3393
-
3394
- constructor(type: string, value: any, path: string, reason?: NativeError, schemaType?: SchemaType);
3395
- }
3396
-
3397
- export class DisconnectedError extends Error {
3398
- name: 'DisconnectedError';
3399
- }
3400
-
3401
- export class DivergentArrayError extends Error {
3402
- name: 'DivergentArrayError';
3403
- }
3404
-
3405
- export class MissingSchemaError extends Error {
3406
- name: 'MissingSchemaError';
3407
- }
3408
-
3409
- export class DocumentNotFoundError extends Error {
3410
- name: 'DocumentNotFoundError';
3411
- result: any;
3412
- numAffected: number;
3413
- filter: any;
3414
- query: any;
3415
- }
3416
-
3417
- export class ObjectExpectedError extends Error {
3418
- name: 'ObjectExpectedError';
3419
- path: string;
3420
- }
3421
-
3422
- export class ObjectParameterError extends Error {
3423
- name: 'ObjectParameterError';
3424
- }
3425
-
3426
- export class OverwriteModelError extends Error {
3427
- name: 'OverwriteModelError';
3428
- }
3429
-
3430
- export class ParallelSaveError extends Error {
3431
- name: 'ParallelSaveError';
3432
- }
3433
-
3434
- export class ParallelValidateError extends Error {
3435
- name: 'ParallelValidateError';
3436
- }
3437
-
3438
- export class MongooseServerSelectionError extends Error {
3439
- name: 'MongooseServerSelectionError';
3440
- }
3441
-
3442
- export class StrictModeError extends Error {
3443
- name: 'StrictModeError';
3444
- isImmutableError: boolean;
3445
- path: string;
3446
- }
3447
-
3448
- export class ValidationError extends Error {
3449
- name: 'ValidationError';
3450
-
3451
- errors: { [path: string]: ValidatorError | CastError | ValidationError };
3452
- addError: (path: string, error: ValidatorError | CastError | ValidationError) => void;
3453
-
3454
- constructor(instance?: Error);
3455
- }
3456
-
3457
- export class ValidatorError extends Error {
3458
- name: 'ValidatorError';
3459
- properties: {
3460
- message: string,
3461
- type?: string,
3462
- path?: string,
3463
- value?: any,
3464
- reason?: any
3465
- };
3466
- kind: string;
3467
- path: string;
3468
- value: any;
3469
- reason?: Error | null;
3470
-
3471
- constructor(properties: {
3472
- message?: string,
3473
- type?: string,
3474
- path?: string,
3475
- value?: any,
3476
- reason?: any
3477
- });
3478
- }
3479
-
3480
- export class VersionError extends Error {
3481
- name: 'VersionError';
3482
- version: number;
3483
- modifiedPaths: Array<string>;
3484
-
3485
- constructor(doc: Document, currentVersion: number, modifiedPaths: Array<string>);
3486
- }
3487
- }
3488
-
3489
2946
  /* for ts-mongoose */
3490
2947
  class mquery {}
3491
2948
  }
2949
+
2950
+ export default mongoose;