mongoose 6.6.4 → 6.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cast.js +17 -6
- package/lib/connection.js +11 -0
- package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +3 -1
- package/lib/helpers/printJestWarning.js +1 -1
- package/lib/helpers/query/castUpdate.js +8 -3
- package/lib/schema/SubdocumentPath.js +1 -0
- package/lib/schema/documentarray.js +3 -3
- package/lib/types/DocumentArray/index.js +1 -1
- package/package.json +1 -1
- package/types/expressions.d.ts +10 -0
- package/types/index.d.ts +1 -1
- package/types/middlewares.d.ts +1 -1
- package/types/pipelinestage.d.ts +2 -1
package/lib/cast.js
CHANGED
|
@@ -264,12 +264,7 @@ module.exports = function cast(schema, obj, options, context) {
|
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
const strict = 'strict' in options ? options.strict : schema.options.strict;
|
|
267
|
-
const strictQuery =
|
|
268
|
-
options.strictQuery :
|
|
269
|
-
'strict' in options ?
|
|
270
|
-
options.strict :
|
|
271
|
-
'strict' in schema._userProvidedOptions ? schema._userProvidedOptions.strict :
|
|
272
|
-
schema.options.strictQuery;
|
|
267
|
+
const strictQuery = getStrictQuery(options, schema._userProvidedOptions, schema.options);
|
|
273
268
|
if (options.upsert && strict) {
|
|
274
269
|
if (strict === 'throw') {
|
|
275
270
|
throw new StrictModeError(path);
|
|
@@ -378,3 +373,19 @@ function _cast(val, numbertype, context) {
|
|
|
378
373
|
}
|
|
379
374
|
}
|
|
380
375
|
}
|
|
376
|
+
|
|
377
|
+
function getStrictQuery(queryOptions, schemaUserProvidedOptions, schemaOptions) {
|
|
378
|
+
if ('strictQuery' in queryOptions) {
|
|
379
|
+
return queryOptions.strictQuery;
|
|
380
|
+
}
|
|
381
|
+
if ('strict' in queryOptions) {
|
|
382
|
+
return queryOptions.strict;
|
|
383
|
+
}
|
|
384
|
+
if ('strictQuery' in schemaUserProvidedOptions) {
|
|
385
|
+
return schemaUserProvidedOptions.strictQuery;
|
|
386
|
+
}
|
|
387
|
+
if ('strict' in schemaUserProvidedOptions) {
|
|
388
|
+
return schemaUserProvidedOptions.strict;
|
|
389
|
+
}
|
|
390
|
+
return schemaOptions.strictQuery;
|
|
391
|
+
}
|
package/lib/connection.js
CHANGED
|
@@ -1534,6 +1534,17 @@ Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
|
|
|
1534
1534
|
*
|
|
1535
1535
|
* Returns a new connection object, with the new db.
|
|
1536
1536
|
*
|
|
1537
|
+
* #### Example:
|
|
1538
|
+
*
|
|
1539
|
+
* // Connect to `initialdb` first
|
|
1540
|
+
* const conn = await mongoose.createConnection('mongodb://localhost:27017/initialdb').asPromise();
|
|
1541
|
+
*
|
|
1542
|
+
* // Creates an un-cached connection to `mydb`
|
|
1543
|
+
* const db = conn.useDb('mydb');
|
|
1544
|
+
* // Creates a cached connection to `mydb2`. All calls to `conn.useDb('mydb2', { useCache: true })` will return the same
|
|
1545
|
+
* // connection instance as opposed to creating a new connection instance
|
|
1546
|
+
* const db2 = conn.useDb('mydb2', { useCache: true });
|
|
1547
|
+
*
|
|
1537
1548
|
* @method useDb
|
|
1538
1549
|
* @memberOf Connection
|
|
1539
1550
|
* @param {String} name The database name
|
|
@@ -12,7 +12,9 @@ module.exports = function prepareDiscriminatorPipeline(pipeline, schema, prefix)
|
|
|
12
12
|
// If the first pipeline stage is a match and it doesn't specify a `__t`
|
|
13
13
|
// key, add the discriminator key to it. This allows for potential
|
|
14
14
|
// aggregation query optimizations not to be disturbed by this feature.
|
|
15
|
-
if (originalPipeline[0] != null &&
|
|
15
|
+
if (originalPipeline[0] != null &&
|
|
16
|
+
originalPipeline[0].$match &&
|
|
17
|
+
(originalPipeline[0].$match[filterKey] === undefined || originalPipeline[0].$match[filterKey] === discriminatorValue)) {
|
|
16
18
|
originalPipeline[0].$match[filterKey] = discriminatorValue;
|
|
17
19
|
// `originalPipeline` is a ref, so there's no need for
|
|
18
20
|
// aggregate._pipeline = originalPipeline
|
|
@@ -9,7 +9,7 @@ if (typeof jest !== 'undefined' && typeof window !== 'undefined') {
|
|
|
9
9
|
'https://mongoosejs.com/docs/jest.html');
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
if (typeof jest !== 'undefined' &&
|
|
12
|
+
if (typeof jest !== 'undefined' && setTimeout.clock != null && typeof setTimeout.clock.Date === 'function') {
|
|
13
13
|
utils.warn('Mongoose: looks like you\'re trying to test a Mongoose app ' +
|
|
14
14
|
'with Jest\'s mock timers enabled. Please make sure you read ' +
|
|
15
15
|
'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
|
|
@@ -196,10 +196,15 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) {
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
const discriminatorKey = (prefix ? prefix + key : key);
|
|
200
|
+
if (
|
|
201
|
+
schema.discriminatorMapping != null &&
|
|
202
|
+
discriminatorKey === schema.options.discriminatorKey &&
|
|
203
|
+
!options.overwriteDiscriminatorKey
|
|
204
|
+
) {
|
|
200
205
|
if (strictMode === 'throw') {
|
|
201
|
-
const err = new Error('Can\'t modify discriminator key "' +
|
|
202
|
-
aggregatedError = _appendError(err, context,
|
|
206
|
+
const err = new Error('Can\'t modify discriminator key "' + discriminatorKey + '" on discriminator model');
|
|
207
|
+
aggregatedError = _appendError(err, context, discriminatorKey, aggregatedError);
|
|
203
208
|
continue;
|
|
204
209
|
} else if (strictMode) {
|
|
205
210
|
delete obj[key];
|
|
@@ -172,6 +172,7 @@ SubdocumentPath.prototype.cast = function(val, doc, init, priorVal, options) {
|
|
|
172
172
|
options = Object.assign({}, options, { priorDoc: priorVal });
|
|
173
173
|
if (init) {
|
|
174
174
|
subdoc = new Constructor(void 0, selected, doc, false, { defaults: false });
|
|
175
|
+
delete subdoc.$__.defaults;
|
|
175
176
|
subdoc.$init(val);
|
|
176
177
|
applyDefaults(subdoc, selected);
|
|
177
178
|
} else {
|
|
@@ -130,12 +130,12 @@ function _createConstructor(schema, options, baseClass) {
|
|
|
130
130
|
Subdocument || (Subdocument = require('../types/ArraySubdocument'));
|
|
131
131
|
|
|
132
132
|
// compile an embedded document for this schema
|
|
133
|
-
function EmbeddedDocument(
|
|
133
|
+
function EmbeddedDocument() {
|
|
134
134
|
Subdocument.apply(this, arguments);
|
|
135
|
-
if (
|
|
135
|
+
if (this.__parentArray == null || this.__parentArray.getArrayParent() == null) {
|
|
136
136
|
return;
|
|
137
137
|
}
|
|
138
|
-
this.$session(
|
|
138
|
+
this.$session(this.__parentArray.getArrayParent().$session());
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
schema._preCompile();
|
|
@@ -57,7 +57,7 @@ function MongooseDocumentArray(values, path, doc) {
|
|
|
57
57
|
// to make more proof against unusual node environments
|
|
58
58
|
if (doc && doc instanceof Document) {
|
|
59
59
|
internals[arrayParentSymbol] = doc;
|
|
60
|
-
internals[arraySchemaSymbol] = doc.
|
|
60
|
+
internals[arraySchemaSymbol] = doc.$__schema.path(path);
|
|
61
61
|
|
|
62
62
|
// `schema.path()` doesn't drill into nested arrays properly yet, see
|
|
63
63
|
// gh-6398, gh-6602. This is a workaround because nested arrays are
|
package/package.json
CHANGED
package/types/expressions.d.ts
CHANGED
|
@@ -1127,6 +1127,16 @@ declare module 'mongoose' {
|
|
|
1127
1127
|
* An expression that resolves to a boolean value used to determine if an element should be included in the output array. The expression references each element of the input array individually with the variable name specified in as.
|
|
1128
1128
|
*/
|
|
1129
1129
|
cond: BooleanExpression;
|
|
1130
|
+
/**
|
|
1131
|
+
* A number expression that restricts the number of matching array elements that $filter returns. You cannot specify a limit less than 1. The matching array elements are returned in the order they appear in the input array.
|
|
1132
|
+
*
|
|
1133
|
+
* If the specified limit is greater than the number of matching array elements, $filter returns all matching array elements.
|
|
1134
|
+
* If the limit is null, $filter returns all matching array elements.
|
|
1135
|
+
*
|
|
1136
|
+
* @version 5.2
|
|
1137
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/#using-the-limit-field
|
|
1138
|
+
*/
|
|
1139
|
+
limit?: NumberExpression;
|
|
1130
1140
|
}
|
|
1131
1141
|
}
|
|
1132
1142
|
|
package/types/index.d.ts
CHANGED
|
@@ -208,7 +208,7 @@ declare module 'mongoose' {
|
|
|
208
208
|
/** Returns a copy of this schema */
|
|
209
209
|
clone<T = this>(): T;
|
|
210
210
|
|
|
211
|
-
discriminator<DisSchema = Schema>(name: string, schema: DisSchema):
|
|
211
|
+
discriminator<DisSchema = Schema>(name: string, schema: DisSchema): this;
|
|
212
212
|
|
|
213
213
|
/** Returns a new schema that has the picked `paths` from this schema. */
|
|
214
214
|
pick<T = this>(paths: string[], options?: SchemaOptions): T;
|
package/types/middlewares.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare module 'mongoose' {
|
|
2
2
|
|
|
3
3
|
type MongooseDocumentMiddleware = 'validate' | 'save' | 'remove' | 'updateOne' | 'deleteOne' | 'init';
|
|
4
|
-
type MongooseQueryMiddleware = 'count' | 'deleteMany' | 'deleteOne' | 'distinct' | 'find' | 'findOne' | 'findOneAndDelete' | 'findOneAndRemove' | 'findOneAndReplace' | 'findOneAndUpdate' | 'remove' | 'replaceOne' | 'update' | 'updateOne' | 'updateMany';
|
|
4
|
+
type MongooseQueryMiddleware = 'count' | 'estimatedDocumentCount' | 'countDocuments' | 'deleteMany' | 'deleteOne' | 'distinct' | 'find' | 'findOne' | 'findOneAndDelete' | 'findOneAndRemove' | 'findOneAndReplace' | 'findOneAndUpdate' | 'remove' | 'replaceOne' | 'update' | 'updateOne' | 'updateMany';
|
|
5
5
|
|
|
6
6
|
type MiddlewareOptions = { document?: boolean, query?: boolean };
|
|
7
7
|
type SchemaPreOptions = MiddlewareOptions;
|
package/types/pipelinestage.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare module 'mongoose' {
|
|
|
8
8
|
| PipelineStage.BucketAuto
|
|
9
9
|
| PipelineStage.CollStats
|
|
10
10
|
| PipelineStage.Count
|
|
11
|
+
| PipelineStage.Densify
|
|
11
12
|
| PipelineStage.Facet
|
|
12
13
|
| PipelineStage.GeoNear
|
|
13
14
|
| PipelineStage.GraphLookup
|
|
@@ -201,7 +202,7 @@ declare module 'mongoose' {
|
|
|
201
202
|
|
|
202
203
|
export interface ReplaceWith {
|
|
203
204
|
/** [`$replaceWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/replaceWith/) */
|
|
204
|
-
$replaceWith: ObjectExpressionOperator;
|
|
205
|
+
$replaceWith: ObjectExpressionOperator | { [field: string]: Expression };
|
|
205
206
|
}
|
|
206
207
|
|
|
207
208
|
export interface Sample {
|