mongoose 6.3.9 → 6.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +65 -36
- package/dist/browser.umd.js +68579 -2
- package/lib/cast/date.js +1 -1
- package/lib/cast/decimal128.js +1 -1
- package/lib/cast/objectid.js +1 -1
- package/lib/cast.js +1 -1
- package/lib/connection.js +47 -5
- package/lib/document.js +48 -8
- package/lib/drivers/node-mongodb-native/index.js +1 -1
- package/lib/error/parallelValidate.js +1 -1
- package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +1 -1
- package/lib/helpers/aggregate/stringifyFunctionOperators.js +1 -1
- package/lib/helpers/arrayDepth.js +1 -1
- package/lib/helpers/cursor/eachAsync.js +1 -1
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
- package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +1 -1
- package/lib/helpers/discriminator/getConstructor.js +1 -1
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
- package/lib/helpers/document/handleSpreadDoc.js +1 -1
- package/lib/helpers/each.js +1 -1
- package/lib/helpers/get.js +1 -1
- package/lib/helpers/getConstructorName.js +1 -1
- package/lib/helpers/getDefaultBulkwriteResult.js +1 -1
- package/lib/helpers/indexes/applySchemaCollation.js +1 -1
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
- package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
- package/lib/helpers/indexes/isTextIndex.js +1 -1
- package/lib/helpers/isMongooseObject.js +1 -1
- package/lib/helpers/isObject.js +1 -1
- package/lib/helpers/isPromise.js +1 -1
- package/lib/helpers/model/applyHooks.js +1 -1
- package/lib/helpers/model/applyStaticHooks.js +1 -1
- package/lib/helpers/once.js +1 -1
- package/lib/helpers/path/flattenObjectWithDottedPaths.js +1 -1
- package/lib/helpers/path/parentPaths.js +1 -1
- package/lib/helpers/path/setDottedPath.js +1 -1
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/SkipPopulateValue.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +1 -1
- package/lib/helpers/populate/assignVals.js +1 -1
- package/lib/helpers/populate/createPopulateQueryFilter.js +1 -1
- package/lib/helpers/populate/getModelsMapForPopulate.js +1 -1
- package/lib/helpers/populate/leanPopulateMap.js +1 -1
- package/lib/helpers/populate/lookupLocalFields.js +1 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/populate/modelNamesFromRefPath.js +1 -1
- package/lib/helpers/populate/removeDeselectedForeignField.js +1 -1
- package/lib/helpers/populate/validateRef.js +1 -1
- package/lib/helpers/printJestWarning.js +1 -1
- package/lib/helpers/processConnectionOptions.js +1 -1
- package/lib/helpers/projection/applyProjection.js +1 -1
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/parseProjection.js +1 -1
- package/lib/helpers/query/applyGlobalOption.js +1 -1
- package/lib/helpers/query/applyQueryMiddleware.js +1 -1
- package/lib/helpers/query/cast$expr.js +1 -1
- package/lib/helpers/query/castFilterPath.js +1 -1
- package/lib/helpers/query/sanitizeFilter.js +1 -1
- package/lib/helpers/query/sanitizeProjection.js +1 -1
- package/lib/helpers/query/trusted.js +1 -1
- package/lib/helpers/query/validOps.js +1 -1
- package/lib/helpers/query/wrapThunk.js +1 -1
- package/lib/helpers/schema/addAutoId.js +1 -1
- package/lib/helpers/schema/applyPlugins.js +1 -1
- package/lib/helpers/schema/cleanPositionalOperators.js +1 -1
- package/lib/helpers/schema/getKeysInSchemaOrder.js +1 -1
- package/lib/helpers/schema/getPath.js +1 -1
- package/lib/helpers/schema/handleIdOption.js +1 -1
- package/lib/helpers/schema/handleTimestampOption.js +1 -1
- package/lib/helpers/specialProperties.js +1 -1
- package/lib/helpers/symbols.js +1 -1
- package/lib/helpers/timers.js +1 -1
- package/lib/helpers/timestamps/setupTimestamps.js +5 -2
- package/lib/helpers/topology/allServersUnknown.js +1 -1
- package/lib/helpers/topology/isAtlas.js +1 -1
- package/lib/helpers/topology/isSSLError.js +1 -1
- package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
- package/lib/helpers/update/castArrayFilters.js +1 -1
- package/lib/helpers/update/moveImmutableProperties.js +1 -1
- package/lib/helpers/update/removeUnusedArrayFilters.js +1 -1
- package/lib/helpers/update/updatedPathsByArrayFilter.js +1 -1
- package/lib/helpers/updateValidators.js +11 -18
- package/lib/index.js +108 -29
- package/lib/model.js +1 -1
- package/lib/options/PopulateOptions.js +1 -1
- package/lib/options/SchemaArrayOptions.js +1 -1
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDocumentArrayOptions.js +1 -1
- package/lib/options/SchemaMapOptions.js +1 -1
- package/lib/options/SchemaNumberOptions.js +1 -1
- package/lib/options/SchemaObjectIdOptions.js +1 -1
- package/lib/options/SchemaSubdocumentOptions.js +1 -1
- package/lib/options/SchemaTypeOptions.js +1 -1
- package/lib/options/VirtualOptions.js +1 -1
- package/lib/options/propertyOptions.js +1 -1
- package/lib/options/removeOptions.js +1 -1
- package/lib/options/saveOptions.js +1 -1
- package/lib/plugins/trackTransaction.js +1 -1
- package/lib/query.js +61 -6
- package/lib/queryhelpers.js +5 -0
- package/lib/schema/array.js +1 -1
- package/lib/schema/date.js +2 -2
- package/lib/schema/documentarray.js +10 -0
- package/lib/schema/number.js +2 -2
- package/lib/schema/string.js +2 -2
- package/lib/schema/symbols.js +1 -1
- package/lib/schema.js +6 -7
- package/lib/statemachine.js +13 -0
- package/lib/types/DocumentArray/methods/index.js +1 -1
- package/lib/utils.js +3 -0
- package/lib/validoptions.js +1 -0
- package/package.json +3 -3
- package/tsconfig.json +1 -0
- package/types/collection.d.ts +1 -1
- package/types/connection.d.ts +5 -0
- package/types/document.d.ts +15 -6
- package/types/expressions.d.ts +2882 -0
- package/types/index.d.ts +46 -17
- package/types/{indizes.d.ts → indexes.d.ts} +2 -2
- package/types/inferschematype.d.ts +173 -0
- package/types/middlewares.d.ts +1 -1
- package/types/models.d.ts +86 -71
- package/types/mongooseoptions.d.ts +9 -1
- package/types/pipelinestage.d.ts +76 -80
- package/types/query.d.ts +1 -1
- package/types/schemaoptions.d.ts +22 -4
- package/types/types.d.ts +3 -1
- package/types/utility.d.ts +9 -0
package/lib/helpers/symbols.js
CHANGED
|
@@ -17,4 +17,4 @@ exports.populateModelSymbol = Symbol('mongoose.PopulateOptions#Model');
|
|
|
17
17
|
exports.schemaTypeSymbol = Symbol('mongoose#schemaType');
|
|
18
18
|
exports.sessionNewDocuments = Symbol('mongoose:ClientSession#newDocuments');
|
|
19
19
|
exports.scopeSymbol = Symbol('mongoose#Document#scope');
|
|
20
|
-
exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
|
|
20
|
+
exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
|
package/lib/helpers/timers.js
CHANGED
|
@@ -31,8 +31,11 @@ module.exports = function setupTimestamps(schema, timestamps) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
if (createdAt && !schema.paths[createdAt]) {
|
|
34
|
-
|
|
34
|
+
const baseImmutableCreatedAt = schema.base.get('timestamps.createdAt.immutable');
|
|
35
|
+
const immutable = baseImmutableCreatedAt != null ? baseImmutableCreatedAt : true;
|
|
36
|
+
schemaAdditions[createdAt] = { [schema.options.typeKey || 'type']: Date, immutable };
|
|
35
37
|
}
|
|
38
|
+
|
|
36
39
|
schema.add(schemaAdditions);
|
|
37
40
|
|
|
38
41
|
schema.pre('save', function(next) {
|
|
@@ -99,4 +102,4 @@ module.exports = function setupTimestamps(schema, timestamps) {
|
|
|
99
102
|
applyTimestampsToChildren(now, this.getUpdate(), this.model.schema);
|
|
100
103
|
next();
|
|
101
104
|
}
|
|
102
|
-
};
|
|
105
|
+
};
|
|
@@ -13,4 +13,4 @@ module.exports = function isSSLError(topologyDescription) {
|
|
|
13
13
|
const descriptions = Array.from(topologyDescription.servers.values());
|
|
14
14
|
return descriptions.length > 0 &&
|
|
15
15
|
descriptions.every(descr => descr.error && descr.error.message.indexOf(nonSSLMessage) !== -1);
|
|
16
|
-
};
|
|
16
|
+
};
|
|
@@ -125,26 +125,19 @@ module.exports = function(query, schema, castedDoc, options, callback) {
|
|
|
125
125
|
validatorsToExecute.push(function(callback) {
|
|
126
126
|
schemaPath.doValidate(v, function(err) {
|
|
127
127
|
if (err) {
|
|
128
|
-
err.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
v.validate(function(err) {
|
|
134
|
-
if (err) {
|
|
135
|
-
if (err.errors) {
|
|
136
|
-
for (const key of Object.keys(err.errors)) {
|
|
137
|
-
const _err = err.errors[key];
|
|
138
|
-
_err.path = updates[i] + '.' + key;
|
|
139
|
-
validationErrors.push(_err);
|
|
140
|
-
}
|
|
141
|
-
} else {
|
|
142
|
-
err.path = updates[i];
|
|
143
|
-
validationErrors.push(err);
|
|
128
|
+
if (err.errors) {
|
|
129
|
+
for (const key of Object.keys(err.errors)) {
|
|
130
|
+
const _err = err.errors[key];
|
|
131
|
+
_err.path = updates[i] + '.' + key;
|
|
132
|
+
validationErrors.push(_err);
|
|
144
133
|
}
|
|
134
|
+
} else {
|
|
135
|
+
err.path = updates[i];
|
|
136
|
+
validationErrors.push(err);
|
|
145
137
|
}
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return callback(null);
|
|
148
141
|
}, context, { updateValidator: true });
|
|
149
142
|
});
|
|
150
143
|
} else {
|
package/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@ require('./driver').set(require('./drivers/node-mongodb-native'));
|
|
|
8
8
|
|
|
9
9
|
const Document = require('./document');
|
|
10
10
|
const EventEmitter = require('events').EventEmitter;
|
|
11
|
+
const Kareem = require('kareem');
|
|
11
12
|
const Schema = require('./schema');
|
|
12
13
|
const SchemaType = require('./schematype');
|
|
13
14
|
const SchemaTypes = require('./schema/index');
|
|
@@ -35,6 +36,7 @@ const shardingPlugin = require('./plugins/sharding');
|
|
|
35
36
|
const trusted = require('./helpers/query/trusted').trusted;
|
|
36
37
|
const sanitizeFilter = require('./helpers/query/sanitizeFilter');
|
|
37
38
|
const isBsonType = require('./helpers/isBsonType');
|
|
39
|
+
const MongooseError = require('./error/mongooseError');
|
|
38
40
|
|
|
39
41
|
const defaultMongooseSymbol = Symbol.for('mongoose:default');
|
|
40
42
|
|
|
@@ -62,6 +64,7 @@ function Mongoose(options) {
|
|
|
62
64
|
this.connections = [];
|
|
63
65
|
this.models = {};
|
|
64
66
|
this.events = new EventEmitter();
|
|
67
|
+
this.__driver = driver.get();
|
|
65
68
|
// default global options
|
|
66
69
|
this.options = Object.assign({
|
|
67
70
|
pluralization: true,
|
|
@@ -135,6 +138,7 @@ Mongoose.prototype.ConnectionStates = STATES;
|
|
|
135
138
|
* uses to communicate with the database. A driver is a Mongoose-specific interface that defines functions
|
|
136
139
|
* like `find()`.
|
|
137
140
|
*
|
|
141
|
+
* @deprecated
|
|
138
142
|
* @memberOf Mongoose
|
|
139
143
|
* @property driver
|
|
140
144
|
* @api public
|
|
@@ -142,6 +146,36 @@ Mongoose.prototype.ConnectionStates = STATES;
|
|
|
142
146
|
|
|
143
147
|
Mongoose.prototype.driver = driver;
|
|
144
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Overwrites the current driver used by this Mongoose instance. A driver is a
|
|
151
|
+
* Mongoose-specific interface that defines functions like `find()`.
|
|
152
|
+
*
|
|
153
|
+
* @memberOf Mongoose
|
|
154
|
+
* @method setDriver
|
|
155
|
+
* @api public
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
Mongoose.prototype.setDriver = function setDriver(driver) {
|
|
159
|
+
const _mongoose = this instanceof Mongoose ? this : mongoose;
|
|
160
|
+
|
|
161
|
+
if (_mongoose.__driver === driver) {
|
|
162
|
+
return _mongoose;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const openConnection = _mongoose.connections && _mongoose.connections.find(conn => conn.readyState !== STATES.disconnected);
|
|
166
|
+
if (openConnection) {
|
|
167
|
+
const msg = 'Cannot modify Mongoose driver if a connection is already open. ' +
|
|
168
|
+
'Call `mongoose.disconnect()` before modifying the driver';
|
|
169
|
+
throw new MongooseError(msg);
|
|
170
|
+
}
|
|
171
|
+
_mongoose.__driver = driver;
|
|
172
|
+
|
|
173
|
+
const Connection = driver.getConnection();
|
|
174
|
+
_mongoose.connections = [new Connection(_mongoose)];
|
|
175
|
+
|
|
176
|
+
return _mongoose;
|
|
177
|
+
};
|
|
178
|
+
|
|
145
179
|
/**
|
|
146
180
|
* Sets mongoose options
|
|
147
181
|
*
|
|
@@ -154,23 +188,26 @@ Mongoose.prototype.driver = driver;
|
|
|
154
188
|
* mongoose.set('debug', function(collectionName, methodName, ...methodArgs) {}); // use custom function to log collection methods + arguments
|
|
155
189
|
*
|
|
156
190
|
* Currently supported options are:
|
|
191
|
+
* - 'applyPluginsToChildSchemas': `true` by default. Set to false to skip applying global plugins to child schemas
|
|
192
|
+
* - 'applyPluginsToDiscriminators': `false` by default. Set to true to apply global plugins to discriminator schemas. This typically isn't necessary because plugins are applied to the base schema and discriminators copy all middleware, methods, statics, and properties from the base schema.
|
|
193
|
+
* - 'autoCreate': Set to `true` to make Mongoose call [`Model.createCollection()`](/docs/api/model.html#model_Model.createCollection) automatically when you create a model with `mongoose.model()` or `conn.model()`. This is useful for testing transactions, change streams, and other features that require the collection to exist.
|
|
194
|
+
* - 'autoIndex': `true` by default. Set to false to disable automatic index creation for all models associated with this Mongoose instance.
|
|
157
195
|
* - 'debug': If `true`, prints the operations mongoose sends to MongoDB to the console. If a writable stream is passed, it will log to that stream, without colorization. If a callback function is passed, it will receive the collection name, the method name, then all arguments passed to the method. For example, if you wanted to replicate the default logging, you could output from the callback `Mongoose: ${collectionName}.${methodName}(${methodArgs.join(', ')})`.
|
|
158
196
|
* - 'returnOriginal': If `false`, changes the default `returnOriginal` option to `findOneAndUpdate()`, `findByIdAndUpdate`, and `findOneAndReplace()` to false. This is equivalent to setting the `new` option to `true` for `findOneAndX()` calls by default. Read our [`findOneAndUpdate()` tutorial](/docs/tutorials/findoneandupdate.html) for more information.
|
|
159
197
|
* - 'bufferCommands': enable/disable mongoose's buffering mechanism for all connections and models
|
|
160
|
-
* - 'cloneSchemas': false by default. Set to `true` to `clone()` all schemas before compiling into a model.
|
|
161
|
-
* - '
|
|
162
|
-
* - '
|
|
163
|
-
* - 'objectIdGetter': true by default. Mongoose adds a getter to MongoDB ObjectId's called `_id` that returns `this` for convenience with populate. Set this to false to remove the getter.
|
|
164
|
-
* - 'runValidators': false by default. Set to true to enable [update validators](/docs/validation.html#update-validators) for all validators by default.
|
|
165
|
-
* - 'toObject': `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to [`toObject()`](/docs/api.html#document_Document-toObject)
|
|
166
|
-
* - 'toJSON': `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to [`toJSON()`](/docs/api.html#document_Document-toJSON), for determining how Mongoose documents get serialized by `JSON.stringify()`
|
|
167
|
-
* - 'strict': true by default, may be `false`, `true`, or `'throw'`. Sets the default strict mode for schemas.
|
|
168
|
-
* - 'strictQuery': same value as 'strict' by default (`true`), may be `false`, `true`, or `'throw'`. Sets the default [strictQuery](/docs/guide.html#strictQuery) mode for schemas.
|
|
169
|
-
* - 'selectPopulatedPaths': true by default. Set to false to opt out of Mongoose adding all fields that you `populate()` to your `select()`. The schema-level option `selectPopulatedPaths` overwrites this one.
|
|
198
|
+
* - 'cloneSchemas': `false` by default. Set to `true` to `clone()` all schemas before compiling into a model.
|
|
199
|
+
* - 'debug': If `true`, prints the operations mongoose sends to MongoDB to the console. If a writable stream is passed, it will log to that stream, without colorization. If a callback function is passed, it will receive the collection name, the method name, then all arugments passed to the method. For example, if you wanted to replicate the default logging, you could output from the callback `Mongoose: ${collectionName}.${methodName}(${methodArgs.join(', ')})`.
|
|
200
|
+
* - 'timestamps.createdAt.immutable': `true` by default. If `false`, it will change the `createdAt` field to be [`immutable: false`](https://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-immutable) which means you can update the `createdAt`
|
|
170
201
|
* - 'maxTimeMS': If set, attaches [maxTimeMS](https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/) to every query
|
|
171
|
-
* - '
|
|
172
|
-
* - 'autoCreate': Set to `true` to make Mongoose call [`Model.createCollection()`](/docs/api/model.html#model_Model.createCollection) automatically when you create a model with `mongoose.model()` or `conn.model()`. This is useful for testing transactions, change streams, and other features that require the collection to exist.
|
|
202
|
+
* - 'objectIdGetter': `true` by default. Mongoose adds a getter to MongoDB ObjectId's called `_id` that returns `this` for convenience with populate. Set this to false to remove the getter.
|
|
173
203
|
* - 'overwriteModels': Set to `true` to default to overwriting models with the same name when calling `mongoose.model()`, as opposed to throwing an `OverwriteModelError`.
|
|
204
|
+
* - 'returnOriginal': If `false`, changes the default `returnOriginal` option to `findOneAndUpdate()`, `findByIdAndUpdate`, and `findOneAndReplace()` to false. This is equivalent to setting the `new` option to `true` for `findOneAndX()` calls by default. Read our [`findOneAndUpdate()` tutorial](/docs/tutorials/findoneandupdate.html) for more information.
|
|
205
|
+
* - 'runValidators': `false` by default. Set to true to enable [update validators](/docs/validation.html#update-validators) for all validators by default.
|
|
206
|
+
* - 'selectPopulatedPaths': `true` by default. Set to false to opt out of Mongoose adding all fields that you `populate()` to your `select()`. The schema-level option `selectPopulatedPaths` overwrites this one.
|
|
207
|
+
* - 'strict': `true` by default, may be `false`, `true`, or `'throw'`. Sets the default strict mode for schemas.
|
|
208
|
+
* - 'strictQuery': same value as 'strict' by default (`true`), may be `false`, `true`, or `'throw'`. Sets the default [strictQuery](/docs/guide.html#strictQuery) mode for schemas.
|
|
209
|
+
* - 'toJSON': `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to [`toJSON()`](/docs/api.html#document_Document-toJSON), for determining how Mongoose documents get serialized by `JSON.stringify()`
|
|
210
|
+
* - 'toObject': `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to [`toObject()`](/docs/api.html#document_Document-toObject)
|
|
174
211
|
*
|
|
175
212
|
* @param {String} key
|
|
176
213
|
* @param {String|Function|Boolean} value
|
|
@@ -273,7 +310,7 @@ Mongoose.prototype.get = Mongoose.prototype.set;
|
|
|
273
310
|
Mongoose.prototype.createConnection = function(uri, options, callback) {
|
|
274
311
|
const _mongoose = this instanceof Mongoose ? this : mongoose;
|
|
275
312
|
|
|
276
|
-
const Connection =
|
|
313
|
+
const Connection = _mongoose.__driver.getConnection();
|
|
277
314
|
const conn = new Connection(_mongoose);
|
|
278
315
|
if (typeof options === 'function') {
|
|
279
316
|
callback = options;
|
|
@@ -467,7 +504,6 @@ Mongoose.prototype.pluralize = function(fn) {
|
|
|
467
504
|
*/
|
|
468
505
|
|
|
469
506
|
Mongoose.prototype.model = function(name, schema, collection, options) {
|
|
470
|
-
|
|
471
507
|
const _mongoose = this instanceof Mongoose ? this : mongoose;
|
|
472
508
|
|
|
473
509
|
if (typeof schema === 'string') {
|
|
@@ -684,7 +720,7 @@ Mongoose.prototype.__defineGetter__('connection', function() {
|
|
|
684
720
|
});
|
|
685
721
|
|
|
686
722
|
Mongoose.prototype.__defineSetter__('connection', function(v) {
|
|
687
|
-
if (v instanceof
|
|
723
|
+
if (v instanceof this.__driver.getConnection()) {
|
|
688
724
|
this.connections[0] = v;
|
|
689
725
|
this.models = v.models;
|
|
690
726
|
}
|
|
@@ -713,18 +749,6 @@ Mongoose.prototype.__defineSetter__('connection', function(v) {
|
|
|
713
749
|
|
|
714
750
|
Mongoose.prototype.connections;
|
|
715
751
|
|
|
716
|
-
/*!
|
|
717
|
-
* Connection
|
|
718
|
-
*/
|
|
719
|
-
|
|
720
|
-
const Connection = driver.get().getConnection();
|
|
721
|
-
|
|
722
|
-
/*!
|
|
723
|
-
* Collection
|
|
724
|
-
*/
|
|
725
|
-
|
|
726
|
-
const Collection = driver.get().Collection;
|
|
727
|
-
|
|
728
752
|
/**
|
|
729
753
|
* The Mongoose Aggregate constructor
|
|
730
754
|
*
|
|
@@ -741,7 +765,14 @@ Mongoose.prototype.Aggregate = Aggregate;
|
|
|
741
765
|
* @api public
|
|
742
766
|
*/
|
|
743
767
|
|
|
744
|
-
Mongoose.prototype
|
|
768
|
+
Object.defineProperty(Mongoose.prototype, 'Collection', {
|
|
769
|
+
get: function() {
|
|
770
|
+
return this.__driver.Collection;
|
|
771
|
+
},
|
|
772
|
+
set: function(Collection) {
|
|
773
|
+
this.__driver.Collection = Collection;
|
|
774
|
+
}
|
|
775
|
+
});
|
|
745
776
|
|
|
746
777
|
/**
|
|
747
778
|
* The Mongoose [Connection](#connection_Connection) constructor
|
|
@@ -752,7 +783,18 @@ Mongoose.prototype.Collection = Collection;
|
|
|
752
783
|
* @api public
|
|
753
784
|
*/
|
|
754
785
|
|
|
755
|
-
Mongoose.prototype
|
|
786
|
+
Object.defineProperty(Mongoose.prototype, 'Connection', {
|
|
787
|
+
get: function() {
|
|
788
|
+
return this.__driver.getConnection();
|
|
789
|
+
},
|
|
790
|
+
set: function(Connection) {
|
|
791
|
+
if (Connection === this.__driver.getConnection()) {
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
this.__driver.getConnection = () => Connection;
|
|
796
|
+
}
|
|
797
|
+
});
|
|
756
798
|
|
|
757
799
|
/**
|
|
758
800
|
* The Mongoose version
|
|
@@ -1178,6 +1220,43 @@ Mongoose.prototype._promiseOrCallback = function(callback, fn, ee) {
|
|
|
1178
1220
|
return promiseOrCallback(callback, fn, ee, this.Promise);
|
|
1179
1221
|
};
|
|
1180
1222
|
|
|
1223
|
+
/**
|
|
1224
|
+
* Use this function in `pre()` middleware to skip calling the wrapped function.
|
|
1225
|
+
*
|
|
1226
|
+
* #### Example:
|
|
1227
|
+
*
|
|
1228
|
+
* schema.pre('save', function() {
|
|
1229
|
+
* // Will skip executing `save()`, but will execute post hooks as if
|
|
1230
|
+
* // `save()` had executed with the result `{ matchedCount: 0 }`
|
|
1231
|
+
* return mongoose.skipMiddlewareFunction({ matchedCount: 0 });
|
|
1232
|
+
* });
|
|
1233
|
+
*
|
|
1234
|
+
* @method skipMiddlewareFunction
|
|
1235
|
+
* @param {any} result
|
|
1236
|
+
* @api public
|
|
1237
|
+
*/
|
|
1238
|
+
|
|
1239
|
+
Mongoose.prototype.skipMiddlewareFunction = Kareem.skipWrappedFunction;
|
|
1240
|
+
|
|
1241
|
+
/**
|
|
1242
|
+
* Use this function in `post()` middleware to replace the result
|
|
1243
|
+
*
|
|
1244
|
+
* #### Example:
|
|
1245
|
+
*
|
|
1246
|
+
* schema.post('find', function(res) {
|
|
1247
|
+
* // Normally you have to modify `res` in place. But with
|
|
1248
|
+
* // `overwriteMiddlewarResult()`, you can make `find()` return a
|
|
1249
|
+
* // completely different value.
|
|
1250
|
+
* return mongoose.overwriteMiddlewareResult(res.filter(doc => !doc.isDeleted));
|
|
1251
|
+
* });
|
|
1252
|
+
*
|
|
1253
|
+
* @method overwriteMiddlewareResult
|
|
1254
|
+
* @param {any} result
|
|
1255
|
+
* @api public
|
|
1256
|
+
*/
|
|
1257
|
+
|
|
1258
|
+
Mongoose.prototype.overwriteMiddlewareResult = Kareem.overwriteResult;
|
|
1259
|
+
|
|
1181
1260
|
/*!
|
|
1182
1261
|
* The exports object is an instance of Mongoose.
|
|
1183
1262
|
*
|
package/lib/model.js
CHANGED
|
@@ -4281,7 +4281,7 @@ Model.validate = function validate(obj, pathsToValidate, context, callback) {
|
|
|
4281
4281
|
|
|
4282
4282
|
for (const path of paths) {
|
|
4283
4283
|
const schemaType = schema.path(path);
|
|
4284
|
-
if (!schemaType || !schemaType.$isMongooseArray) {
|
|
4284
|
+
if (!schemaType || !schemaType.$isMongooseArray || schemaType.$isMongooseDocumentArray) {
|
|
4285
4285
|
continue;
|
|
4286
4286
|
}
|
|
4287
4287
|
|