mongoose 6.3.6 → 6.3.9
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/lib/connection.js +3 -4
- package/lib/document.js +18 -9
- package/lib/error/disconnected.js +3 -4
- package/lib/helpers/update/castArrayFilters.js +3 -0
- package/lib/index.js +0 -4
- package/lib/options/SchemaTypeOptions.js +13 -0
- package/lib/schema/SubdocumentPath.js +7 -0
- package/lib/schema.js +1 -0
- package/package.json +3 -3
- package/types/aggregate.d.ts +3 -0
- package/types/helpers.d.ts +3 -4
- package/types/index.d.ts +8 -8
- package/types/models.d.ts +4 -4
- package/types/schematypes.d.ts +19 -10
package/lib/connection.js
CHANGED
|
@@ -9,6 +9,7 @@ const EventEmitter = require('events').EventEmitter;
|
|
|
9
9
|
const Schema = require('./schema');
|
|
10
10
|
const STATES = require('./connectionstate');
|
|
11
11
|
const MongooseError = require('./error/index');
|
|
12
|
+
const DisconnectedError = require('./error/disconnected');
|
|
12
13
|
const SyncIndexesError = require('./error/syncIndexes');
|
|
13
14
|
const PromiseProvider = require('./promise_provider');
|
|
14
15
|
const ServerSelectionError = require('./error/serverSelection');
|
|
@@ -565,8 +566,7 @@ function _wrapConnHelper(fn) {
|
|
|
565
566
|
const argsWithoutCb = typeof cb === 'function' ?
|
|
566
567
|
Array.prototype.slice.call(arguments, 0, arguments.length - 1) :
|
|
567
568
|
Array.prototype.slice.call(arguments);
|
|
568
|
-
const disconnectedError = new
|
|
569
|
-
' was disconnected when calling `' + fn.name + '`');
|
|
569
|
+
const disconnectedError = new DisconnectedError(this.id, fn.name);
|
|
570
570
|
|
|
571
571
|
return promiseOrCallback(cb, cb => {
|
|
572
572
|
immediate(() => {
|
|
@@ -1260,8 +1260,7 @@ Connection.prototype.deleteModel = function(name) {
|
|
|
1260
1260
|
*/
|
|
1261
1261
|
|
|
1262
1262
|
Connection.prototype.watch = function(pipeline, options) {
|
|
1263
|
-
const disconnectedError = new
|
|
1264
|
-
' was disconnected when calling `watch()`');
|
|
1263
|
+
const disconnectedError = new DisconnectedError(this.id, 'watch');
|
|
1265
1264
|
|
|
1266
1265
|
const changeStreamThunk = cb => {
|
|
1267
1266
|
immediate(() => {
|
package/lib/document.js
CHANGED
|
@@ -136,7 +136,6 @@ function Document(obj, fields, skipId, options) {
|
|
|
136
136
|
// excluded fields
|
|
137
137
|
if (utils.isPOJO(fields)) {
|
|
138
138
|
exclude = isExclusive(fields);
|
|
139
|
-
|
|
140
139
|
this.$__.fields = fields;
|
|
141
140
|
this.$__.exclude = exclude;
|
|
142
141
|
}
|
|
@@ -641,7 +640,11 @@ Document.prototype.$__buildDoc = function(obj, fields, skipId, exclude, hasInclu
|
|
|
641
640
|
for (let i = 0; i < len; ++i) {
|
|
642
641
|
const piece = path[i];
|
|
643
642
|
|
|
644
|
-
|
|
643
|
+
if (!curPath.length) {
|
|
644
|
+
curPath = piece;
|
|
645
|
+
} else {
|
|
646
|
+
curPath += '.' + piece;
|
|
647
|
+
}
|
|
645
648
|
|
|
646
649
|
// support excluding intermediary levels
|
|
647
650
|
if (exclude === true) {
|
|
@@ -1045,8 +1048,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
1045
1048
|
type = undefined;
|
|
1046
1049
|
}
|
|
1047
1050
|
|
|
1048
|
-
|
|
1049
|
-
const merge = options.merge;
|
|
1051
|
+
const merge = options && options.merge;
|
|
1050
1052
|
const adhoc = type && type !== true;
|
|
1051
1053
|
const constructing = type === true;
|
|
1052
1054
|
let adhocs;
|
|
@@ -1056,7 +1058,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
1056
1058
|
let key;
|
|
1057
1059
|
let prefix;
|
|
1058
1060
|
|
|
1059
|
-
const strict = 'strict' in options
|
|
1061
|
+
const strict = options && 'strict' in options
|
|
1060
1062
|
? options.strict
|
|
1061
1063
|
: this.$__.strictMode;
|
|
1062
1064
|
|
|
@@ -1087,7 +1089,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
1087
1089
|
|
|
1088
1090
|
// `_skipMinimizeTopLevel` is because we may have deleted the top-level
|
|
1089
1091
|
// nested key to ensure key order.
|
|
1090
|
-
const _skipMinimizeTopLevel = options._skipMinimizeTopLevel || false;
|
|
1092
|
+
const _skipMinimizeTopLevel = options && options._skipMinimizeTopLevel || false;
|
|
1091
1093
|
if (len === 0 && _skipMinimizeTopLevel) {
|
|
1092
1094
|
delete options._skipMinimizeTopLevel;
|
|
1093
1095
|
if (val) {
|
|
@@ -1565,7 +1567,7 @@ Document.prototype.set = Document.prototype.$set;
|
|
|
1565
1567
|
*/
|
|
1566
1568
|
|
|
1567
1569
|
Document.prototype.$__shouldModify = function(pathToMark, path, options, constructing, parts, schema, val, priorVal) {
|
|
1568
|
-
if (options._skipMarkModified) {
|
|
1570
|
+
if (options && options._skipMarkModified) {
|
|
1569
1571
|
return false;
|
|
1570
1572
|
}
|
|
1571
1573
|
if (this.$isNew) {
|
|
@@ -3386,7 +3388,7 @@ Document.prototype.$getAllSubdocs = function() {
|
|
|
3386
3388
|
}, seed);
|
|
3387
3389
|
} else if (val && !Array.isArray(val) && val.$isSingleNested) {
|
|
3388
3390
|
seed = Object.keys(val._doc).reduce(function(seed, path) {
|
|
3389
|
-
return docReducer(val
|
|
3391
|
+
return docReducer(val, seed, path);
|
|
3390
3392
|
}, seed);
|
|
3391
3393
|
seed.push(val);
|
|
3392
3394
|
} else if (val && utils.isMongooseDocumentArray(val)) {
|
|
@@ -3929,12 +3931,19 @@ function applySchemaTypeTransforms(self, json) {
|
|
|
3929
3931
|
const schematype = schema.paths[path];
|
|
3930
3932
|
if (typeof schematype.options.transform === 'function') {
|
|
3931
3933
|
const val = self.$get(path);
|
|
3934
|
+
if (val === undefined) {
|
|
3935
|
+
continue;
|
|
3936
|
+
}
|
|
3932
3937
|
const transformedValue = schematype.options.transform.call(self, val);
|
|
3933
3938
|
throwErrorIfPromise(path, transformedValue);
|
|
3934
3939
|
utils.setValue(path, transformedValue, json);
|
|
3935
3940
|
} else if (schematype.$embeddedSchemaType != null &&
|
|
3936
3941
|
typeof schematype.$embeddedSchemaType.options.transform === 'function') {
|
|
3937
|
-
const
|
|
3942
|
+
const val = self.$get(path);
|
|
3943
|
+
if (val === undefined) {
|
|
3944
|
+
continue;
|
|
3945
|
+
}
|
|
3946
|
+
const vals = [].concat(val);
|
|
3938
3947
|
const transform = schematype.$embeddedSchemaType.options.transform;
|
|
3939
3948
|
for (let i = 0; i < vals.length; ++i) {
|
|
3940
3949
|
const transformedValue = transform.call(self, vals[i]);
|
|
@@ -16,10 +16,9 @@ class DisconnectedError extends MongooseError {
|
|
|
16
16
|
/**
|
|
17
17
|
* @param {String} connectionString
|
|
18
18
|
*/
|
|
19
|
-
constructor(
|
|
20
|
-
super('
|
|
21
|
-
|
|
22
|
-
'`server.reconnectInterval` to something higher.');
|
|
19
|
+
constructor(id, fnName) {
|
|
20
|
+
super('Connection ' + id +
|
|
21
|
+
' was disconnected when calling `' + fnName + '()`');
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
|
|
@@ -15,6 +15,9 @@ module.exports = function castArrayFilters(query) {
|
|
|
15
15
|
if (query._mongooseOptions.strict != null) {
|
|
16
16
|
strictQuery = query._mongooseOptions.strict;
|
|
17
17
|
}
|
|
18
|
+
if (query.model && query.model.base.options.strictQuery != null) {
|
|
19
|
+
strictQuery = query.model.base.options.strictQuery;
|
|
20
|
+
}
|
|
18
21
|
if (schema._userProvidedOptions.strictQuery != null) {
|
|
19
22
|
strictQuery = schema._userProvidedOptions.strictQuery;
|
|
20
23
|
}
|
package/lib/index.js
CHANGED
|
@@ -260,8 +260,6 @@ Mongoose.prototype.get = Mongoose.prototype.set;
|
|
|
260
260
|
* @param {String} [options.user] username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility.
|
|
261
261
|
* @param {String} [options.pass] password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility.
|
|
262
262
|
* @param {Boolean} [options.autoIndex=true] Mongoose-specific option. Set to false to disable automatic index creation for all models associated with this connection.
|
|
263
|
-
* @param {Number} [options.reconnectTries=30] If you're connected to a single server or mongos proxy (as opposed to a replica set), the MongoDB driver will try to reconnect every `reconnectInterval` milliseconds for `reconnectTries` times, and give up afterward. When the driver gives up, the mongoose connection emits a `reconnectFailed` event. This option does nothing for replica set connections.
|
|
264
|
-
* @param {Number} [options.reconnectInterval=1000] See `reconnectTries` option above.
|
|
265
263
|
* @param {Class} [options.promiseLibrary] Sets the [underlying driver's promise library](https://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html).
|
|
266
264
|
* @param {Number} [options.maxPoolSize=5] The maximum number of sockets the MongoDB driver will keep open for this connection. Keep in mind that MongoDB only allows one operation per socket at a time, so you may want to increase this if you find you have a few slow queries that are blocking faster queries from proceeding. See [Slow Trains in MongoDB and Node.js](https://thecodebarbarian.com/slow-trains-in-mongodb-and-nodejs).
|
|
267
265
|
* @param {Number} [options.minPoolSize=1] The minimum number of sockets the MongoDB driver will keep open for this connection. Keep in mind that MongoDB only allows one operation per socket at a time, so you may want to increase this if you find you have a few slow queries that are blocking faster queries from proceeding. See [Slow Trains in MongoDB and Node.js](https://thecodebarbarian.com/slow-trains-in-mongodb-and-nodejs).
|
|
@@ -323,8 +321,6 @@ Mongoose.prototype.createConnection = function(uri, options, callback) {
|
|
|
323
321
|
* @param {Number} [options.serverSelectionTimeoutMS] If `useUnifiedTopology = true`, the MongoDB driver will try to find a server to send any given operation to, and keep retrying for `serverSelectionTimeoutMS` milliseconds before erroring out. If not set, the MongoDB driver defaults to using `30000` (30 seconds).
|
|
324
322
|
* @param {Number} [options.heartbeatFrequencyMS] If `useUnifiedTopology = true`, the MongoDB driver sends a heartbeat every `heartbeatFrequencyMS` to check on the status of the connection. A heartbeat is subject to `serverSelectionTimeoutMS`, so the MongoDB driver will retry failed heartbeats for up to 30 seconds by default. Mongoose only emits a `'disconnected'` event after a heartbeat has failed, so you may want to decrease this setting to reduce the time between when your server goes down and when Mongoose emits `'disconnected'`. We recommend you do **not** set this setting below 1000, too many heartbeats can lead to performance degradation.
|
|
325
323
|
* @param {Boolean} [options.autoIndex=true] Mongoose-specific option. Set to false to disable automatic index creation for all models associated with this connection.
|
|
326
|
-
* @param {Number} [options.reconnectTries=30] If you're connected to a single server or mongos proxy (as opposed to a replica set), the MongoDB driver will try to reconnect every `reconnectInterval` milliseconds for `reconnectTries` times, and give up afterward. When the driver gives up, the mongoose connection emits a `reconnectFailed` event. This option does nothing for replica set connections.
|
|
327
|
-
* @param {Number} [options.reconnectInterval=1000] See `reconnectTries` option above.
|
|
328
324
|
* @param {Class} [options.promiseLibrary] Sets the [underlying driver's promise library](https://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html).
|
|
329
325
|
* @param {Number} [options.connectTimeoutMS=30000] How long the MongoDB driver will wait before killing a socket due to inactivity _during initial connection_. Defaults to 30000. This option is passed transparently to [Node.js' `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback).
|
|
330
326
|
* @param {Number} [options.socketTimeoutMS=30000] How long the MongoDB driver will wait before killing a socket due to inactivity _after initial connection_. A socket may be inactive because of either no activity or a long-running operation. This is set to `30000` by default, you should set this to 2-3x your longest running operation if you expect some of your database operations to run longer than 20 seconds. This option is passed to [Node.js `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback) after the MongoDB driver successfully completes.
|
|
@@ -119,6 +119,19 @@ Object.defineProperty(SchemaTypeOptions.prototype, 'default', opts);
|
|
|
119
119
|
|
|
120
120
|
Object.defineProperty(SchemaTypeOptions.prototype, 'ref', opts);
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* The path in the document that `populate()` should use to find the model
|
|
124
|
+
* to use.
|
|
125
|
+
*
|
|
126
|
+
* @api public
|
|
127
|
+
* @property ref
|
|
128
|
+
* @memberOf SchemaTypeOptions
|
|
129
|
+
* @type Function|String
|
|
130
|
+
* @instance
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
Object.defineProperty(SchemaTypeOptions.prototype, 'refPath', opts);
|
|
134
|
+
|
|
122
135
|
/**
|
|
123
136
|
* Whether to include or exclude this path by default when loading documents
|
|
124
137
|
* using `find()`, `findOne()`, etc.
|
|
@@ -33,6 +33,13 @@ module.exports = SubdocumentPath;
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
function SubdocumentPath(schema, path, options) {
|
|
36
|
+
const schemaTypeIdOption = SubdocumentPath.defaultOptions &&
|
|
37
|
+
SubdocumentPath.defaultOptions._id;
|
|
38
|
+
if (schemaTypeIdOption != null) {
|
|
39
|
+
options = options || {};
|
|
40
|
+
options._id = schemaTypeIdOption;
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
schema = handleIdOption(schema, options);
|
|
37
44
|
|
|
38
45
|
this.caster = _createConstructor(schema);
|
package/lib/schema.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.3.
|
|
4
|
+
"version": "6.3.9",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"test": "mocha --exit ./test/*.test.js",
|
|
97
97
|
"test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js",
|
|
98
98
|
"test-tsd": "node ./test/types/check-types-filename && tsd",
|
|
99
|
-
"tdd": "mocha ./test/*.test.js
|
|
99
|
+
"tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}",
|
|
100
100
|
"test-coverage": "nyc --reporter=html --reporter=text npm test",
|
|
101
101
|
"ts-benchmark": "ts-benchmark -p ./benchmarks/typescript/simple -f 17 18 29 32",
|
|
102
102
|
"ts-benchmark-watch": "ts-benchmark -p ./benchmarks/typescript/simple -w ./types -i -s -f 17 18 29 32 -b master"
|
|
@@ -145,4 +145,4 @@
|
|
|
145
145
|
"target": "ES2017"
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
}
|
|
148
|
+
}
|
package/types/aggregate.d.ts
CHANGED
package/types/helpers.d.ts
CHANGED
|
@@ -20,14 +20,13 @@ declare module 'mongoose' {
|
|
|
20
20
|
* of an ObjectId.
|
|
21
21
|
*/
|
|
22
22
|
function isObjectIdOrHexString(v: mongodb.ObjectId): true;
|
|
23
|
-
function isObjectIdOrHexString(v: string): boolean;
|
|
23
|
+
function isObjectIdOrHexString(v: mongodb.ObjectId | string): boolean;
|
|
24
24
|
function isObjectIdOrHexString(v: any): false;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Returns true if Mongoose can cast the given value to an ObjectId, or
|
|
28
28
|
* false otherwise.
|
|
29
29
|
*/
|
|
30
|
-
function isValidObjectId(v: mongodb.ObjectId): true;
|
|
31
|
-
function isValidObjectId(v: Types.ObjectId): true;
|
|
30
|
+
function isValidObjectId(v: mongodb.ObjectId | Types.ObjectId): true;
|
|
32
31
|
function isValidObjectId(v: any): boolean;
|
|
33
|
-
}
|
|
32
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -211,14 +211,14 @@ declare module 'mongoose' {
|
|
|
211
211
|
plugin(fn: (schema: Schema<DocType>, opts?: any) => void, opts?: any): this;
|
|
212
212
|
|
|
213
213
|
/** Defines a post hook for the model. */
|
|
214
|
-
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PostMiddlewareFunction<T>): this;
|
|
215
|
-
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T>): this;
|
|
216
|
-
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PostMiddlewareFunction<T>): this;
|
|
217
|
-
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T>): this;
|
|
218
|
-
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PostMiddlewareFunction<T, Array<
|
|
219
|
-
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, Array<
|
|
220
|
-
post<T = M>(method: 'insertMany' | RegExp, fn: PostMiddlewareFunction<T>): this;
|
|
221
|
-
post<T = M>(method: 'insertMany' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T>): this;
|
|
214
|
+
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PostMiddlewareFunction<T, T>): this;
|
|
215
|
+
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
|
|
216
|
+
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PostMiddlewareFunction<T, T>): this;
|
|
217
|
+
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
|
|
218
|
+
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PostMiddlewareFunction<T, Array<AggregateExtract<T>>>): this;
|
|
219
|
+
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, Array<AggregateExtract<T>>>): this;
|
|
220
|
+
post<T = M>(method: 'insertMany' | RegExp, fn: PostMiddlewareFunction<T, T>): this;
|
|
221
|
+
post<T = M>(method: 'insertMany' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
|
|
222
222
|
|
|
223
223
|
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
|
|
224
224
|
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
|
package/types/models.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
declare module 'mongoose' {
|
|
2
2
|
import mongodb = require('mongodb');
|
|
3
3
|
|
|
4
|
-
export interface AcceptsDiscriminator
|
|
4
|
+
export interface AcceptsDiscriminator {
|
|
5
5
|
/** Adds a discriminator type. */
|
|
6
|
-
discriminator<D>(name: string | number, schema: Schema
|
|
6
|
+
discriminator<D>(name: string | number, schema: Schema, value?: string | number | ObjectId): Model<D>;
|
|
7
7
|
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string | number | ObjectId): U;
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -116,7 +116,7 @@ declare module 'mongoose' {
|
|
|
116
116
|
const Model: Model<any>;
|
|
117
117
|
interface Model<T, TQueryHelpers = {}, TMethodsAndOverrides = {}, TVirtuals = {}> extends
|
|
118
118
|
NodeJS.EventEmitter,
|
|
119
|
-
AcceptsDiscriminator
|
|
119
|
+
AcceptsDiscriminator,
|
|
120
120
|
IndexManager,
|
|
121
121
|
SessionStarter {
|
|
122
122
|
new <DocType = AnyKeys<T> & AnyObject>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<T, TMethodsAndOverrides, TVirtuals>;
|
|
@@ -416,4 +416,4 @@ declare module 'mongoose' {
|
|
|
416
416
|
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(obj: object): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
417
417
|
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
418
418
|
}
|
|
419
|
-
}
|
|
419
|
+
}
|
package/types/schematypes.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ declare module 'mongoose' {
|
|
|
37
37
|
/** The various Mongoose SchemaTypes. */
|
|
38
38
|
const SchemaTypes: typeof Schema.Types;
|
|
39
39
|
|
|
40
|
+
type DefaultType<T> = T extends Schema.Types.Mixed ? any : Partial<ExtractMongooseArray<T>>;
|
|
41
|
+
|
|
40
42
|
class SchemaTypeOptions<T> {
|
|
41
43
|
type?:
|
|
42
44
|
T extends string ? StringSchemaDefinition :
|
|
@@ -74,13 +76,20 @@ declare module 'mongoose' {
|
|
|
74
76
|
* The default value for this path. If a function, Mongoose executes the function
|
|
75
77
|
* and uses the return value as the default.
|
|
76
78
|
*/
|
|
77
|
-
default?: T
|
|
79
|
+
default?: DefaultType<T> | ((this: any, doc: any) => DefaultType<T>) | null;
|
|
78
80
|
|
|
79
81
|
/**
|
|
80
82
|
* The model that `populate()` should use if populating this path.
|
|
81
83
|
*/
|
|
82
84
|
ref?: string | Model<any> | ((this: any, doc: any) => string | Model<any>);
|
|
83
85
|
|
|
86
|
+
/**
|
|
87
|
+
* The path in the document that `populate()` should use to find the model
|
|
88
|
+
* to use.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
refPath?: string | ((this: any, doc: any) => string);
|
|
92
|
+
|
|
84
93
|
/**
|
|
85
94
|
* Whether to include or exclude this path by default when loading documents
|
|
86
95
|
* using `find()`, `findOne()`, etc.
|
|
@@ -269,17 +278,17 @@ declare module 'mongoose' {
|
|
|
269
278
|
|
|
270
279
|
namespace Schema {
|
|
271
280
|
namespace Types {
|
|
272
|
-
class Array
|
|
281
|
+
class Array extends SchemaType implements AcceptsDiscriminator {
|
|
273
282
|
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
274
283
|
static schemaName: 'Array';
|
|
275
284
|
|
|
276
285
|
static options: { castNonArrays: boolean; };
|
|
277
286
|
|
|
278
287
|
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
|
|
279
|
-
discriminator<D>(name: string | number, schema: Schema
|
|
288
|
+
discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
|
|
280
289
|
|
|
281
290
|
/** The schematype embedded in this array */
|
|
282
|
-
caster?: SchemaType
|
|
291
|
+
caster?: SchemaType;
|
|
283
292
|
|
|
284
293
|
/**
|
|
285
294
|
* Adds an enum validator if this is an array of strings or numbers. Equivalent to
|
|
@@ -329,17 +338,17 @@ declare module 'mongoose' {
|
|
|
329
338
|
static schemaName: 'Decimal128';
|
|
330
339
|
}
|
|
331
340
|
|
|
332
|
-
class DocumentArray
|
|
341
|
+
class DocumentArray extends SchemaType implements AcceptsDiscriminator {
|
|
333
342
|
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
334
343
|
static schemaName: 'DocumentArray';
|
|
335
344
|
|
|
336
345
|
static options: { castNonArrays: boolean; };
|
|
337
346
|
|
|
338
|
-
discriminator<D>(name: string | number, schema: Schema
|
|
347
|
+
discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
|
|
339
348
|
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
|
|
340
349
|
|
|
341
350
|
/** The schema used for documents in this array */
|
|
342
|
-
schema: Schema
|
|
351
|
+
schema: Schema;
|
|
343
352
|
|
|
344
353
|
/** The constructor used for subdocuments in this array */
|
|
345
354
|
caster?: typeof Types.Subdocument;
|
|
@@ -377,15 +386,15 @@ declare module 'mongoose' {
|
|
|
377
386
|
auto(turnOn: boolean): this;
|
|
378
387
|
}
|
|
379
388
|
|
|
380
|
-
class Subdocument
|
|
389
|
+
class Subdocument extends SchemaType implements AcceptsDiscriminator {
|
|
381
390
|
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
382
391
|
static schemaName: string;
|
|
383
392
|
|
|
384
393
|
/** The document's schema */
|
|
385
|
-
schema: Schema
|
|
394
|
+
schema: Schema;
|
|
386
395
|
|
|
387
396
|
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
|
|
388
|
-
discriminator<D>(name: string | number, schema: Schema
|
|
397
|
+
discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
|
|
389
398
|
}
|
|
390
399
|
|
|
391
400
|
class String extends SchemaType {
|