mongoose 6.2.4 → 6.2.5
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/CHANGELOG.md +18 -0
- package/dist/browser.umd.js +42 -35
- package/lib/helpers/isSimpleValidator.js +22 -0
- package/lib/helpers/populate/assignVals.js +11 -3
- package/lib/helpers/populate/getModelsMapForPopulate.js +1 -1
- package/lib/helpers/query/castUpdate.js +21 -6
- package/lib/index.js +38 -2
- package/lib/model.js +6 -6
- package/lib/query.js +8 -8
- package/lib/schema/array.js +1 -0
- package/lib/schematype.js +15 -14
- package/package.json +1 -1
- package/types/{Connection.d.ts → connection.d.ts} +0 -0
- package/types/cursor.ts +48 -0
- package/types/{Error.d.ts → error.d.ts} +0 -0
- package/types/index.d.ts +23 -261
- package/types/{PipelineStage.d.ts → pipelinestage.d.ts} +0 -0
- package/types/schemaoptions.d.ts +183 -0
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
/// <reference path="./
|
|
2
|
-
/// <reference path="./
|
|
3
|
-
/// <reference path="./
|
|
1
|
+
/// <reference path="./connection.d.ts" />
|
|
2
|
+
/// <reference path="./cursor.ts" />
|
|
3
|
+
/// <reference path="./error.d.ts" />
|
|
4
|
+
/// <reference path="./pipelinestage.d.ts" />
|
|
5
|
+
/// <reference path="./schemaoptions.d.ts" />
|
|
4
6
|
|
|
5
7
|
import events = require('events');
|
|
6
8
|
import mongodb = require('mongodb');
|
|
@@ -119,6 +121,13 @@ declare module 'mongoose' {
|
|
|
119
121
|
export function isValidObjectId(v: Types.ObjectId): true;
|
|
120
122
|
export function isValidObjectId(v: any): boolean;
|
|
121
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Returns true if the given value is a Mongoose ObjectId (using `instanceof`) or if the
|
|
126
|
+
* given value is a 24 character hex string, which is the most commonly used string representation
|
|
127
|
+
* of an ObjectId.
|
|
128
|
+
*/
|
|
129
|
+
export function isObjectIdOrHexString(v: any): boolean;
|
|
130
|
+
|
|
122
131
|
export function model<T>(name: string, schema?: Schema<T, any, any> | Schema<T & Document, any, any>, collection?: string, options?: CompileModelOptions): Model<T>;
|
|
123
132
|
export function model<T, U, TQueryHelpers = {}>(
|
|
124
133
|
name: string,
|
|
@@ -1226,7 +1235,7 @@ declare module 'mongoose' {
|
|
|
1226
1235
|
statics: { [name: string]: (this: M, ...args: any[]) => any };
|
|
1227
1236
|
|
|
1228
1237
|
/** Creates a virtual type with the given name. */
|
|
1229
|
-
virtual(name: string, options?: VirtualTypeOptions): VirtualType;
|
|
1238
|
+
virtual<T = HydratedDocument<DocType, TInstanceMethods>>(name: string, options?: VirtualTypeOptions<T>): VirtualType;
|
|
1230
1239
|
|
|
1231
1240
|
/** Object of currently defined virtuals on this schema */
|
|
1232
1241
|
virtuals: any;
|
|
@@ -1256,183 +1265,16 @@ declare module 'mongoose' {
|
|
|
1256
1265
|
typeof SchemaType |
|
|
1257
1266
|
Schema<any, any, any> |
|
|
1258
1267
|
Schema<any, any, any>[] |
|
|
1259
|
-
SchemaTypeOptions<T extends undefined ? any : T
|
|
1268
|
+
SchemaTypeOptions<T extends undefined ? any : Unpacked<T>>[] |
|
|
1260
1269
|
Function[] |
|
|
1261
1270
|
SchemaDefinition<T> |
|
|
1262
|
-
SchemaDefinition<T
|
|
1271
|
+
SchemaDefinition<Unpacked<T>>[] |
|
|
1263
1272
|
typeof SchemaTypes.Mixed;
|
|
1264
1273
|
|
|
1265
1274
|
type SchemaDefinition<T = undefined> = T extends undefined
|
|
1266
1275
|
? { [path: string]: SchemaDefinitionProperty; }
|
|
1267
1276
|
: { [path in keyof T]?: SchemaDefinitionProperty<T[path]>; };
|
|
1268
1277
|
|
|
1269
|
-
interface SchemaOptions {
|
|
1270
|
-
/**
|
|
1271
|
-
* By default, Mongoose's init() function creates all the indexes defined in your model's schema by
|
|
1272
|
-
* calling Model.createIndexes() after you successfully connect to MongoDB. If you want to disable
|
|
1273
|
-
* automatic index builds, you can set autoIndex to false.
|
|
1274
|
-
*/
|
|
1275
|
-
autoIndex?: boolean;
|
|
1276
|
-
/**
|
|
1277
|
-
* If set to `true`, Mongoose will call Model.createCollection() to create the underlying collection
|
|
1278
|
-
* in MongoDB if autoCreate is set to true. Calling createCollection() sets the collection's default
|
|
1279
|
-
* collation based on the collation option and establishes the collection as a capped collection if
|
|
1280
|
-
* you set the capped schema option.
|
|
1281
|
-
*/
|
|
1282
|
-
autoCreate?: boolean;
|
|
1283
|
-
/**
|
|
1284
|
-
* By default, mongoose buffers commands when the connection goes down until the driver manages to reconnect.
|
|
1285
|
-
* To disable buffering, set bufferCommands to false.
|
|
1286
|
-
*/
|
|
1287
|
-
bufferCommands?: boolean;
|
|
1288
|
-
/**
|
|
1289
|
-
* If bufferCommands is on, this option sets the maximum amount of time Mongoose buffering will wait before
|
|
1290
|
-
* throwing an error. If not specified, Mongoose will use 10000 (10 seconds).
|
|
1291
|
-
*/
|
|
1292
|
-
bufferTimeoutMS?: number;
|
|
1293
|
-
/**
|
|
1294
|
-
* Mongoose supports MongoDBs capped collections. To specify the underlying MongoDB collection be capped, set
|
|
1295
|
-
* the capped option to the maximum size of the collection in bytes.
|
|
1296
|
-
*/
|
|
1297
|
-
capped?: boolean | number | { size?: number; max?: number; autoIndexId?: boolean; };
|
|
1298
|
-
/** Sets a default collation for every query and aggregation. */
|
|
1299
|
-
collation?: mongodb.CollationOptions;
|
|
1300
|
-
|
|
1301
|
-
/** The timeseries option to use when creating the model's collection. */
|
|
1302
|
-
timeseries?: mongodb.TimeSeriesCollectionOptions;
|
|
1303
|
-
|
|
1304
|
-
/**
|
|
1305
|
-
* Mongoose by default produces a collection name by passing the model name to the utils.toCollectionName
|
|
1306
|
-
* method. This method pluralizes the name. Set this option if you need a different name for your collection.
|
|
1307
|
-
*/
|
|
1308
|
-
collection?: string;
|
|
1309
|
-
/**
|
|
1310
|
-
* When you define a [discriminator](/docs/discriminators.html), Mongoose adds a path to your
|
|
1311
|
-
* schema that stores which discriminator a document is an instance of. By default, Mongoose
|
|
1312
|
-
* adds an `__t` path, but you can set `discriminatorKey` to overwrite this default.
|
|
1313
|
-
*/
|
|
1314
|
-
discriminatorKey?: string;
|
|
1315
|
-
/** defaults to false. */
|
|
1316
|
-
emitIndexErrors?: boolean;
|
|
1317
|
-
excludeIndexes?: any;
|
|
1318
|
-
/**
|
|
1319
|
-
* Mongoose assigns each of your schemas an id virtual getter by default which returns the document's _id field
|
|
1320
|
-
* cast to a string, or in the case of ObjectIds, its hexString.
|
|
1321
|
-
*/
|
|
1322
|
-
id?: boolean;
|
|
1323
|
-
/**
|
|
1324
|
-
* Mongoose assigns each of your schemas an _id field by default if one is not passed into the Schema
|
|
1325
|
-
* constructor. The type assigned is an ObjectId to coincide with MongoDB's default behavior. If you
|
|
1326
|
-
* don't want an _id added to your schema at all, you may disable it using this option.
|
|
1327
|
-
*/
|
|
1328
|
-
_id?: boolean;
|
|
1329
|
-
/**
|
|
1330
|
-
* Mongoose will, by default, "minimize" schemas by removing empty objects. This behavior can be
|
|
1331
|
-
* overridden by setting minimize option to false. It will then store empty objects.
|
|
1332
|
-
*/
|
|
1333
|
-
minimize?: boolean;
|
|
1334
|
-
/**
|
|
1335
|
-
* Optimistic concurrency is a strategy to ensure the document you're updating didn't change between when you
|
|
1336
|
-
* loaded it using find() or findOne(), and when you update it using save(). Set to `true` to enable
|
|
1337
|
-
* optimistic concurrency.
|
|
1338
|
-
*/
|
|
1339
|
-
optimisticConcurrency?: boolean;
|
|
1340
|
-
/**
|
|
1341
|
-
* If `plugin()` called with tags, Mongoose will only apply plugins to schemas that have
|
|
1342
|
-
* a matching tag in `pluginTags`
|
|
1343
|
-
*/
|
|
1344
|
-
pluginTags?: string[];
|
|
1345
|
-
/**
|
|
1346
|
-
* Allows setting query#read options at the schema level, providing us a way to apply default ReadPreferences
|
|
1347
|
-
* to all queries derived from a model.
|
|
1348
|
-
*/
|
|
1349
|
-
read?: string;
|
|
1350
|
-
/** Allows setting write concern at the schema level. */
|
|
1351
|
-
writeConcern?: WriteConcern;
|
|
1352
|
-
/** defaults to true. */
|
|
1353
|
-
safe?: boolean | { w?: number | string; wtimeout?: number; j?: boolean };
|
|
1354
|
-
/**
|
|
1355
|
-
* The shardKey option is used when we have a sharded MongoDB architecture. Each sharded collection is
|
|
1356
|
-
* given a shard key which must be present in all insert/update operations. We just need to set this
|
|
1357
|
-
* schema option to the same shard key and we'll be all set.
|
|
1358
|
-
*/
|
|
1359
|
-
shardKey?: Record<string, unknown>;
|
|
1360
|
-
/**
|
|
1361
|
-
* The strict option, (enabled by default), ensures that values passed to our model constructor that were not
|
|
1362
|
-
* specified in our schema do not get saved to the db.
|
|
1363
|
-
*/
|
|
1364
|
-
strict?: boolean | 'throw';
|
|
1365
|
-
/**
|
|
1366
|
-
* equal to `strict` by default, may be `false`, `true`, or `'throw'`. Sets the default
|
|
1367
|
-
* [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
|
|
1368
|
-
*/
|
|
1369
|
-
strictQuery?: boolean | 'throw';
|
|
1370
|
-
/** Exactly the same as the toObject option but only applies when the document's toJSON method is called. */
|
|
1371
|
-
toJSON?: ToObjectOptions;
|
|
1372
|
-
/**
|
|
1373
|
-
* Documents have a toObject method which converts the mongoose document into a plain JavaScript object.
|
|
1374
|
-
* This method accepts a few options. Instead of applying these options on a per-document basis, we may
|
|
1375
|
-
* declare the options at the schema level and have them applied to all of the schema's documents by
|
|
1376
|
-
* default.
|
|
1377
|
-
*/
|
|
1378
|
-
toObject?: ToObjectOptions;
|
|
1379
|
-
/**
|
|
1380
|
-
* By default, if you have an object with key 'type' in your schema, mongoose will interpret it as a
|
|
1381
|
-
* type declaration. However, for applications like geoJSON, the 'type' property is important. If you want to
|
|
1382
|
-
* control which key mongoose uses to find type declarations, set the 'typeKey' schema option.
|
|
1383
|
-
*/
|
|
1384
|
-
typeKey?: string;
|
|
1385
|
-
|
|
1386
|
-
/**
|
|
1387
|
-
* By default, documents are automatically validated before they are saved to the database. This is to
|
|
1388
|
-
* prevent saving an invalid document. If you want to handle validation manually, and be able to save
|
|
1389
|
-
* objects which don't pass validation, you can set validateBeforeSave to false.
|
|
1390
|
-
*/
|
|
1391
|
-
validateBeforeSave?: boolean;
|
|
1392
|
-
/**
|
|
1393
|
-
* The versionKey is a property set on each document when first created by Mongoose. This keys value
|
|
1394
|
-
* contains the internal revision of the document. The versionKey option is a string that represents
|
|
1395
|
-
* the path to use for versioning. The default is '__v'.
|
|
1396
|
-
*/
|
|
1397
|
-
versionKey?: string | boolean;
|
|
1398
|
-
/**
|
|
1399
|
-
* By default, Mongoose will automatically select() any populated paths for you, unless you explicitly exclude them.
|
|
1400
|
-
*/
|
|
1401
|
-
selectPopulatedPaths?: boolean;
|
|
1402
|
-
/**
|
|
1403
|
-
* skipVersioning allows excluding paths from versioning (i.e., the internal revision will not be
|
|
1404
|
-
* incremented even if these paths are updated). DO NOT do this unless you know what you're doing.
|
|
1405
|
-
* For subdocuments, include this on the parent document using the fully qualified path.
|
|
1406
|
-
*/
|
|
1407
|
-
skipVersioning?: any;
|
|
1408
|
-
/**
|
|
1409
|
-
* Validation errors in a single nested schema are reported
|
|
1410
|
-
* both on the child and on the parent schema.
|
|
1411
|
-
* Set storeSubdocValidationError to false on the child schema
|
|
1412
|
-
* to make Mongoose only report the parent error.
|
|
1413
|
-
*/
|
|
1414
|
-
storeSubdocValidationError?: boolean;
|
|
1415
|
-
/**
|
|
1416
|
-
* The timestamps option tells mongoose to assign createdAt and updatedAt fields to your schema. The type
|
|
1417
|
-
* assigned is Date. By default, the names of the fields are createdAt and updatedAt. Customize the
|
|
1418
|
-
* field names by setting timestamps.createdAt and timestamps.updatedAt.
|
|
1419
|
-
*/
|
|
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
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
interface SchemaTimestampsConfig {
|
|
1431
|
-
createdAt?: boolean | string;
|
|
1432
|
-
updatedAt?: boolean | string;
|
|
1433
|
-
currentTime?: () => (NativeDate | number);
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
1278
|
type Unpacked<T> = T extends (infer U)[] ?
|
|
1437
1279
|
U :
|
|
1438
1280
|
T extends ReadonlyArray<infer U> ? U : T;
|
|
@@ -1657,15 +1499,15 @@ declare module 'mongoose' {
|
|
|
1657
1499
|
|
|
1658
1500
|
type InferId<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
|
|
1659
1501
|
|
|
1660
|
-
interface VirtualTypeOptions {
|
|
1502
|
+
interface VirtualTypeOptions<HydratedDocType = Document> {
|
|
1661
1503
|
/** If `ref` is not nullish, this becomes a populated virtual. */
|
|
1662
1504
|
ref?: string | Function;
|
|
1663
1505
|
|
|
1664
1506
|
/** The local field to populate on if this is a populated virtual. */
|
|
1665
|
-
localField?: string |
|
|
1507
|
+
localField?: string | ((this: HydratedDocType, doc: HydratedDocType) => string);
|
|
1666
1508
|
|
|
1667
1509
|
/** The foreign field to populate on if this is a populated virtual. */
|
|
1668
|
-
foreignField?: string |
|
|
1510
|
+
foreignField?: string | ((this: HydratedDocType, doc: HydratedDocType) => string);
|
|
1669
1511
|
|
|
1670
1512
|
/**
|
|
1671
1513
|
* By default, a populated virtual is an array. If you set `justOne`,
|
|
@@ -2053,7 +1895,7 @@ declare module 'mongoose' {
|
|
|
2053
1895
|
* Returns a wrapper around a [mongodb driver cursor](http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html).
|
|
2054
1896
|
* A QueryCursor exposes a Streams3 interface, as well as a `.next()` function.
|
|
2055
1897
|
*/
|
|
2056
|
-
cursor(options?:
|
|
1898
|
+
cursor(options?: QueryOptions): Cursor<DocType, QueryOptions>;
|
|
2057
1899
|
|
|
2058
1900
|
/**
|
|
2059
1901
|
* Declare and/or execute this query as a `deleteMany()` operation. Works like
|
|
@@ -2274,7 +2116,7 @@ declare module 'mongoose' {
|
|
|
2274
2116
|
polygon(path: string, ...coordinatePairs: number[][]): this;
|
|
2275
2117
|
|
|
2276
2118
|
/** Specifies paths which should be populated with other documents. */
|
|
2277
|
-
populate<Paths = {}>(path: string
|
|
2119
|
+
populate<Paths = {}>(path: string, select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersectionWithNull<ResultType, Paths>, DocType, THelpers, RawDocType>;
|
|
2278
2120
|
populate<Paths = {}>(options: PopulateOptions | Array<PopulateOptions>): QueryWithHelpers<UnpackedIntersectionWithNull<ResultType, Paths>, DocType, THelpers, RawDocType>;
|
|
2279
2121
|
|
|
2280
2122
|
/** Get/set the current projection (AKA fields). Pass `null` to remove the current projection. */
|
|
@@ -2500,7 +2342,7 @@ declare module 'mongoose' {
|
|
|
2500
2342
|
$each: Type;
|
|
2501
2343
|
};
|
|
2502
2344
|
|
|
2503
|
-
type SortValues = -1 | 1 | 'asc' | 'desc';
|
|
2345
|
+
type SortValues = -1 | 1 | 'asc' | 'ascending' | 'desc' | 'descending';
|
|
2504
2346
|
|
|
2505
2347
|
type ArrayOperator<Type> = {
|
|
2506
2348
|
$each: Type;
|
|
@@ -2618,49 +2460,6 @@ declare module 'mongoose' {
|
|
|
2618
2460
|
T extends Document ? RawDocType :
|
|
2619
2461
|
T;
|
|
2620
2462
|
|
|
2621
|
-
class QueryCursor<DocType> extends stream.Readable {
|
|
2622
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<DocType>;
|
|
2623
|
-
|
|
2624
|
-
/**
|
|
2625
|
-
* Adds a [cursor flag](http://mongodb.github.io/node-mongodb-native/2.2/api/Cursor.html#addCursorFlag).
|
|
2626
|
-
* Useful for setting the `noCursorTimeout` and `tailable` flags.
|
|
2627
|
-
*/
|
|
2628
|
-
addCursorFlag(flag: string, value: boolean): this;
|
|
2629
|
-
|
|
2630
|
-
/**
|
|
2631
|
-
* Marks this cursor as closed. Will stop streaming and subsequent calls to
|
|
2632
|
-
* `next()` will error.
|
|
2633
|
-
*/
|
|
2634
|
-
close(): Promise<void>;
|
|
2635
|
-
close(callback: CallbackWithoutResult): void;
|
|
2636
|
-
|
|
2637
|
-
/**
|
|
2638
|
-
* Execute `fn` for every document(s) in the cursor. If batchSize is provided
|
|
2639
|
-
* `fn` will be executed for each batch of documents. If `fn` returns a promise,
|
|
2640
|
-
* will wait for the promise to resolve before iterating on to the next one.
|
|
2641
|
-
* Returns a promise that resolves when done.
|
|
2642
|
-
*/
|
|
2643
|
-
eachAsync(fn: (doc: DocType) => any, options?: { parallel?: number }): Promise<void>;
|
|
2644
|
-
eachAsync(fn: (doc: DocType[]) => any, options: { parallel?: number, batchSize: number }): Promise<void>;
|
|
2645
|
-
eachAsync(fn: (doc: DocType) => any, options?: { parallel?: number, batchSize?: number }, cb?: CallbackWithoutResult): void;
|
|
2646
|
-
eachAsync(fn: (doc: DocType[]) => any, options: { parallel?: number, batchSize: number }, cb?: CallbackWithoutResult): void;
|
|
2647
|
-
|
|
2648
|
-
/**
|
|
2649
|
-
* Registers a transform function which subsequently maps documents retrieved
|
|
2650
|
-
* via the streams interface or `.next()`
|
|
2651
|
-
*/
|
|
2652
|
-
map<ResultType>(fn: (res: DocType) => ResultType): QueryCursor<ResultType>;
|
|
2653
|
-
|
|
2654
|
-
/**
|
|
2655
|
-
* Get the next document from this cursor. Will return `null` when there are
|
|
2656
|
-
* no documents left.
|
|
2657
|
-
*/
|
|
2658
|
-
next(): Promise<DocType>;
|
|
2659
|
-
next(callback: Callback<DocType | null>): void;
|
|
2660
|
-
|
|
2661
|
-
options: any;
|
|
2662
|
-
}
|
|
2663
|
-
|
|
2664
2463
|
class Aggregate<R> {
|
|
2665
2464
|
/**
|
|
2666
2465
|
* Returns an asyncIterator for use with [`for/await/of` loops](https://thecodebarbarian.com/getting-started-with-async-iterators-in-node-js
|
|
@@ -2702,7 +2501,7 @@ declare module 'mongoose' {
|
|
|
2702
2501
|
/**
|
|
2703
2502
|
* Sets the cursor option for the aggregation query (ignored for < 2.6.0).
|
|
2704
2503
|
*/
|
|
2705
|
-
cursor(options?: Record<string, unknown>):
|
|
2504
|
+
cursor<DocType = any>(options?: Record<string, unknown>): Cursor<DocType>;
|
|
2706
2505
|
|
|
2707
2506
|
/** Executes the aggregate pipeline on the currently bound Model. */
|
|
2708
2507
|
exec(callback?: Callback<R>): Promise<R>;
|
|
@@ -2790,7 +2589,7 @@ declare module 'mongoose' {
|
|
|
2790
2589
|
skip(num: number): this;
|
|
2791
2590
|
|
|
2792
2591
|
/** Appends a new $sort operator to this aggregate pipeline. */
|
|
2793
|
-
sort(arg: PipelineStage.Sort['$sort']): this;
|
|
2592
|
+
sort(arg: string | Record<string, SortValues> | PipelineStage.Sort['$sort']): this;
|
|
2794
2593
|
|
|
2795
2594
|
/** Provides promise for aggregate. */
|
|
2796
2595
|
then: Promise<R>['then'];
|
|
@@ -2808,43 +2607,6 @@ declare module 'mongoose' {
|
|
|
2808
2607
|
unwind(...args: PipelineStage.Unwind['$unwind'][]): this;
|
|
2809
2608
|
}
|
|
2810
2609
|
|
|
2811
|
-
class AggregationCursor extends stream.Readable {
|
|
2812
|
-
/**
|
|
2813
|
-
* Adds a [cursor flag](http://mongodb.github.io/node-mongodb-native/2.2/api/Cursor.html#addCursorFlag).
|
|
2814
|
-
* Useful for setting the `noCursorTimeout` and `tailable` flags.
|
|
2815
|
-
*/
|
|
2816
|
-
addCursorFlag(flag: string, value: boolean): this;
|
|
2817
|
-
|
|
2818
|
-
/**
|
|
2819
|
-
* Marks this cursor as closed. Will stop streaming and subsequent calls to
|
|
2820
|
-
* `next()` will error.
|
|
2821
|
-
*/
|
|
2822
|
-
close(): Promise<void>;
|
|
2823
|
-
close(callback: CallbackWithoutResult): void;
|
|
2824
|
-
|
|
2825
|
-
/**
|
|
2826
|
-
* Execute `fn` for every document(s) in the cursor. If batchSize is provided
|
|
2827
|
-
* `fn` will be executed for each batch of documents. If `fn` returns a promise,
|
|
2828
|
-
* will wait for the promise to resolve before iterating on to the next one.
|
|
2829
|
-
* Returns a promise that resolves when done.
|
|
2830
|
-
*/
|
|
2831
|
-
eachAsync(fn: (doc: any) => any, options?: { parallel?: number, batchSize?: number }): Promise<void>;
|
|
2832
|
-
eachAsync(fn: (doc: any) => any, options?: { parallel?: number, batchSize?: number }, cb?: CallbackWithoutResult): void;
|
|
2833
|
-
|
|
2834
|
-
/**
|
|
2835
|
-
* Registers a transform function which subsequently maps documents retrieved
|
|
2836
|
-
* via the streams interface or `.next()`
|
|
2837
|
-
*/
|
|
2838
|
-
map(fn: (res: any) => any): this;
|
|
2839
|
-
|
|
2840
|
-
/**
|
|
2841
|
-
* Get the next document from this cursor. Will return `null` when there are
|
|
2842
|
-
* no documents left.
|
|
2843
|
-
*/
|
|
2844
|
-
next(): Promise<any>;
|
|
2845
|
-
next(callback: Callback): void;
|
|
2846
|
-
}
|
|
2847
|
-
|
|
2848
2610
|
class SchemaType {
|
|
2849
2611
|
/** SchemaType constructor */
|
|
2850
2612
|
constructor(path: string, options?: AnyObject, instance?: string);
|
|
File without changes
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import mongodb = require('mongodb');
|
|
2
|
+
|
|
3
|
+
declare module 'mongoose' {
|
|
4
|
+
|
|
5
|
+
interface SchemaTimestampsConfig {
|
|
6
|
+
createdAt?: boolean | string;
|
|
7
|
+
updatedAt?: boolean | string;
|
|
8
|
+
currentTime?: () => (NativeDate | number);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface SchemaOptions {
|
|
12
|
+
/**
|
|
13
|
+
* By default, Mongoose's init() function creates all the indexes defined in your model's schema by
|
|
14
|
+
* calling Model.createIndexes() after you successfully connect to MongoDB. If you want to disable
|
|
15
|
+
* automatic index builds, you can set autoIndex to false.
|
|
16
|
+
*/
|
|
17
|
+
autoIndex?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* If set to `true`, Mongoose will call Model.createCollection() to create the underlying collection
|
|
20
|
+
* in MongoDB if autoCreate is set to true. Calling createCollection() sets the collection's default
|
|
21
|
+
* collation based on the collation option and establishes the collection as a capped collection if
|
|
22
|
+
* you set the capped schema option.
|
|
23
|
+
*/
|
|
24
|
+
autoCreate?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* By default, mongoose buffers commands when the connection goes down until the driver manages to reconnect.
|
|
27
|
+
* To disable buffering, set bufferCommands to false.
|
|
28
|
+
*/
|
|
29
|
+
bufferCommands?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* If bufferCommands is on, this option sets the maximum amount of time Mongoose buffering will wait before
|
|
32
|
+
* throwing an error. If not specified, Mongoose will use 10000 (10 seconds).
|
|
33
|
+
*/
|
|
34
|
+
bufferTimeoutMS?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Mongoose supports MongoDBs capped collections. To specify the underlying MongoDB collection be capped, set
|
|
37
|
+
* the capped option to the maximum size of the collection in bytes.
|
|
38
|
+
*/
|
|
39
|
+
capped?: boolean | number | { size?: number; max?: number; autoIndexId?: boolean; };
|
|
40
|
+
/** Sets a default collation for every query and aggregation. */
|
|
41
|
+
collation?: mongodb.CollationOptions;
|
|
42
|
+
|
|
43
|
+
/** The timeseries option to use when creating the model's collection. */
|
|
44
|
+
timeseries?: mongodb.TimeSeriesCollectionOptions;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Mongoose by default produces a collection name by passing the model name to the utils.toCollectionName
|
|
48
|
+
* method. This method pluralizes the name. Set this option if you need a different name for your collection.
|
|
49
|
+
*/
|
|
50
|
+
collection?: string;
|
|
51
|
+
/**
|
|
52
|
+
* When you define a [discriminator](/docs/discriminators.html), Mongoose adds a path to your
|
|
53
|
+
* schema that stores which discriminator a document is an instance of. By default, Mongoose
|
|
54
|
+
* adds an `__t` path, but you can set `discriminatorKey` to overwrite this default.
|
|
55
|
+
*
|
|
56
|
+
* @default '__t'
|
|
57
|
+
*/
|
|
58
|
+
discriminatorKey?: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Option for nested Schemas.
|
|
62
|
+
*
|
|
63
|
+
* If true, skip building indexes on this schema's path.
|
|
64
|
+
*
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
excludeIndexes?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Mongoose assigns each of your schemas an id virtual getter by default which returns the document's _id field
|
|
70
|
+
* cast to a string, or in the case of ObjectIds, its hexString.
|
|
71
|
+
*/
|
|
72
|
+
id?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Mongoose assigns each of your schemas an _id field by default if one is not passed into the Schema
|
|
75
|
+
* constructor. The type assigned is an ObjectId to coincide with MongoDB's default behavior. If you
|
|
76
|
+
* don't want an _id added to your schema at all, you may disable it using this option.
|
|
77
|
+
*/
|
|
78
|
+
_id?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Mongoose will, by default, "minimize" schemas by removing empty objects. This behavior can be
|
|
81
|
+
* overridden by setting minimize option to false. It will then store empty objects.
|
|
82
|
+
*/
|
|
83
|
+
minimize?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Optimistic concurrency is a strategy to ensure the document you're updating didn't change between when you
|
|
86
|
+
* loaded it using find() or findOne(), and when you update it using save(). Set to `true` to enable
|
|
87
|
+
* optimistic concurrency.
|
|
88
|
+
*/
|
|
89
|
+
optimisticConcurrency?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* If `plugin()` called with tags, Mongoose will only apply plugins to schemas that have
|
|
92
|
+
* a matching tag in `pluginTags`
|
|
93
|
+
*/
|
|
94
|
+
pluginTags?: string[];
|
|
95
|
+
/**
|
|
96
|
+
* Allows setting query#read options at the schema level, providing us a way to apply default ReadPreferences
|
|
97
|
+
* to all queries derived from a model.
|
|
98
|
+
*/
|
|
99
|
+
read?: string;
|
|
100
|
+
/** Allows setting write concern at the schema level. */
|
|
101
|
+
writeConcern?: WriteConcern;
|
|
102
|
+
/** defaults to true. */
|
|
103
|
+
safe?: boolean | { w?: number | string; wtimeout?: number; j?: boolean };
|
|
104
|
+
/**
|
|
105
|
+
* The shardKey option is used when we have a sharded MongoDB architecture. Each sharded collection is
|
|
106
|
+
* given a shard key which must be present in all insert/update operations. We just need to set this
|
|
107
|
+
* schema option to the same shard key and we'll be all set.
|
|
108
|
+
*/
|
|
109
|
+
shardKey?: Record<string, unknown>;
|
|
110
|
+
/**
|
|
111
|
+
* The strict option, (enabled by default), ensures that values passed to our model constructor that were not
|
|
112
|
+
* specified in our schema do not get saved to the db.
|
|
113
|
+
*/
|
|
114
|
+
strict?: boolean | 'throw';
|
|
115
|
+
/**
|
|
116
|
+
* equal to `strict` by default, may be `false`, `true`, or `'throw'`. Sets the default
|
|
117
|
+
* [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
|
|
118
|
+
*/
|
|
119
|
+
strictQuery?: boolean | 'throw';
|
|
120
|
+
/** Exactly the same as the toObject option but only applies when the document's toJSON method is called. */
|
|
121
|
+
toJSON?: ToObjectOptions;
|
|
122
|
+
/**
|
|
123
|
+
* Documents have a toObject method which converts the mongoose document into a plain JavaScript object.
|
|
124
|
+
* This method accepts a few options. Instead of applying these options on a per-document basis, we may
|
|
125
|
+
* declare the options at the schema level and have them applied to all of the schema's documents by
|
|
126
|
+
* default.
|
|
127
|
+
*/
|
|
128
|
+
toObject?: ToObjectOptions;
|
|
129
|
+
/**
|
|
130
|
+
* By default, if you have an object with key 'type' in your schema, mongoose will interpret it as a
|
|
131
|
+
* type declaration. However, for applications like geoJSON, the 'type' property is important. If you want to
|
|
132
|
+
* control which key mongoose uses to find type declarations, set the 'typeKey' schema option.
|
|
133
|
+
*/
|
|
134
|
+
typeKey?: string;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* By default, documents are automatically validated before they are saved to the database. This is to
|
|
138
|
+
* prevent saving an invalid document. If you want to handle validation manually, and be able to save
|
|
139
|
+
* objects which don't pass validation, you can set validateBeforeSave to false.
|
|
140
|
+
*/
|
|
141
|
+
validateBeforeSave?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* The versionKey is a property set on each document when first created by Mongoose. This keys value
|
|
144
|
+
* contains the internal revision of the document. The versionKey option is a string that represents
|
|
145
|
+
* the path to use for versioning. The default is '__v'.
|
|
146
|
+
*
|
|
147
|
+
* @default '__v'
|
|
148
|
+
*/
|
|
149
|
+
versionKey?: string | boolean;
|
|
150
|
+
/**
|
|
151
|
+
* By default, Mongoose will automatically select() any populated paths for you, unless you explicitly exclude them.
|
|
152
|
+
*
|
|
153
|
+
* @default true
|
|
154
|
+
*/
|
|
155
|
+
selectPopulatedPaths?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* skipVersioning allows excluding paths from versioning (i.e., the internal revision will not be
|
|
158
|
+
* incremented even if these paths are updated). DO NOT do this unless you know what you're doing.
|
|
159
|
+
* For subdocuments, include this on the parent document using the fully qualified path.
|
|
160
|
+
*/
|
|
161
|
+
skipVersioning?: {[key: string]: boolean; };
|
|
162
|
+
/**
|
|
163
|
+
* Validation errors in a single nested schema are reported
|
|
164
|
+
* both on the child and on the parent schema.
|
|
165
|
+
* Set storeSubdocValidationError to false on the child schema
|
|
166
|
+
* to make Mongoose only report the parent error.
|
|
167
|
+
*/
|
|
168
|
+
storeSubdocValidationError?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* The timestamps option tells mongoose to assign createdAt and updatedAt fields to your schema. The type
|
|
171
|
+
* assigned is Date. By default, the names of the fields are createdAt and updatedAt. Customize the
|
|
172
|
+
* field names by setting timestamps.createdAt and timestamps.updatedAt.
|
|
173
|
+
*/
|
|
174
|
+
timestamps?: boolean | SchemaTimestampsConfig;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Using `save`, `isNew`, and other Mongoose reserved names as schema path names now triggers a warning, not an error.
|
|
178
|
+
* You can suppress the warning by setting { supressReservedKeysWarning: true } schema options. Keep in mind that this
|
|
179
|
+
* can break plugins that rely on these reserved names.
|
|
180
|
+
*/
|
|
181
|
+
supressReservedKeysWarning?: boolean
|
|
182
|
+
}
|
|
183
|
+
}
|