mongoose 9.12.2 → 9.12.3
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 +1 -1
- package/lib/document.js +1 -1
- package/lib/helpers/query/cast$expr.js +16 -0
- package/lib/helpers/updateValidators.js +14 -1
- package/lib/model.js +4 -2
- package/lib/schema/documentArray.js +2 -1
- package/package.json +2 -2
- package/types/expressions.d.ts +1 -1
- package/types/index.d.ts +3 -0
package/lib/connection.js
CHANGED
|
@@ -1826,7 +1826,7 @@ Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
|
|
|
1826
1826
|
*/
|
|
1827
1827
|
|
|
1828
1828
|
/**
|
|
1829
|
-
* Removes the database connection with the given name created with
|
|
1829
|
+
* Removes the database connection with the given name created with `useDb()`.
|
|
1830
1830
|
*
|
|
1831
1831
|
* Throws an error if the database connection was not found.
|
|
1832
1832
|
*
|
package/lib/document.js
CHANGED
|
@@ -3717,7 +3717,7 @@ function _checkImmutableSubpaths(subdoc, schematype, priorVal) {
|
|
|
3717
3717
|
* @param {number|string} [options.w] set the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#w-option). Overrides the [schema-level `writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern)
|
|
3718
3718
|
* @param {boolean} [options.j] set to true for MongoDB to wait until this `save()` has been [journaled before resolving the returned promise](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option). Overrides the [schema-level `writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern)
|
|
3719
3719
|
* @param {number} [options.wtimeout] sets a [timeout for the write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout). Overrides the [schema-level `writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern).
|
|
3720
|
-
* @param {boolean} [options.checkKeys=
|
|
3720
|
+
* @param {boolean} [options.checkKeys=false] if `true`, the MongoDB driver rejects keys that start with '$' or contain '.' when this `save()` inserts a new document. Leave it off when saving changes to an existing document: the driver also checks update operators like `$set`, so the update fails. See [restrictions on field names](https://www.mongodb.com/docs/manual/reference/limits/#Restrictions-on-Field-Names)
|
|
3721
3721
|
* @param {boolean} [options.timestamps=true] if `false` and [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this `save()`.
|
|
3722
3722
|
* @param {Array} [options.pathsToSave] An array of paths that tell mongoose to only validate and save the paths in `pathsToSave`.
|
|
3723
3723
|
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const CastError = require('../../error/cast');
|
|
4
4
|
const StrictModeError = require('../../error/strict');
|
|
5
5
|
const castNumber = require('../../cast/number');
|
|
6
|
+
const isPOJO = require('../isPOJO');
|
|
6
7
|
const omitUndefined = require('../omitUndefined');
|
|
7
8
|
|
|
8
9
|
const booleanComparison = new Set(['$and', '$or']);
|
|
@@ -181,6 +182,21 @@ function castIn(val, schema, strictQuery) {
|
|
|
181
182
|
throw new Error('Path must be an array for $in');
|
|
182
183
|
}
|
|
183
184
|
|
|
185
|
+
// The search value may be an expression, like '$field' or { $add: [...] }.
|
|
186
|
+
// Documents and buffers have `$` keys too, so they are still cast below.
|
|
187
|
+
if (!isLiteral(search) && (typeof search === 'string' || isPOJO(search))) {
|
|
188
|
+
return [
|
|
189
|
+
_castExpression(search, schema, strictQuery),
|
|
190
|
+
path
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
if (typeof search === 'object' && search != null && search.$literal != null) {
|
|
194
|
+
return [
|
|
195
|
+
{ $literal: schematype.embeddedSchemaType.cast(search.$literal) },
|
|
196
|
+
path
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
|
|
184
200
|
return [
|
|
185
201
|
schematype.embeddedSchemaType.cast(search),
|
|
186
202
|
path
|
|
@@ -89,7 +89,7 @@ module.exports = async function updateValidators(query, schema, castedDoc, optio
|
|
|
89
89
|
if (schemaPath == null) {
|
|
90
90
|
continue;
|
|
91
91
|
}
|
|
92
|
-
if (schemaPath.instance === 'Mixed' && schemaPath.path !== updates[i]) {
|
|
92
|
+
if (schemaPath.instance === 'Mixed' && schemaPath.path !== updates[i] && isUnderneathMixed(schema, updates[i])) {
|
|
93
93
|
continue;
|
|
94
94
|
}
|
|
95
95
|
if (isPull[updates[i]] && schemaPath.$isMongooseArray) {
|
|
@@ -192,3 +192,16 @@ function hasValidatedAncestor(alreadyValidated, path) {
|
|
|
192
192
|
}
|
|
193
193
|
return false;
|
|
194
194
|
}
|
|
195
|
+
|
|
196
|
+
/*!
|
|
197
|
+
* Returns true if the parent of `path` is a Mixed path, so `path` is a key
|
|
198
|
+
* inside a Mixed value rather than a path in the schema.
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
function isUnderneathMixed(schema, path) {
|
|
202
|
+
const lastDot = path.lastIndexOf('.');
|
|
203
|
+
if (lastDot === -1) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
return schema._getSchema(path.slice(0, lastDot))?.instance === 'Mixed';
|
|
207
|
+
}
|
package/lib/model.js
CHANGED
|
@@ -624,7 +624,7 @@ function generateVersionError(doc, modifiedPaths, defaultPaths) {
|
|
|
624
624
|
* @param {number|string} [options.w] set the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#w-option). Overrides the [schema-level `writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern)
|
|
625
625
|
* @param {boolean} [options.j] set to true for MongoDB to wait until this `save()` has been [journaled before resolving the returned promise](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option). Overrides the [schema-level `writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern)
|
|
626
626
|
* @param {number} [options.wtimeout] sets a [timeout for the write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout). Overrides the [schema-level `writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern).
|
|
627
|
-
* @param {boolean} [options.checkKeys=
|
|
627
|
+
* @param {boolean} [options.checkKeys=false] if `true`, the MongoDB driver rejects keys that start with '$' or contain '.' when this `save()` inserts a new document. Leave it off when saving changes to an existing document: the driver also checks update operators like `$set`, so the update fails. See [restrictions on field names](https://docs.mongodb.com/manual/reference/limits/#mongodb-limit-Restrictions-on-Field-Names)
|
|
628
628
|
* @param {boolean} [options.timestamps=true] if `false` and [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this `save()`.
|
|
629
629
|
* @param {Array} [options.pathsToSave] An array of paths that tell mongoose to only validate and save the paths in `pathsToSave`.
|
|
630
630
|
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
@@ -4388,7 +4388,9 @@ Model.validate = async function validate(obj, pathsOrOptions, context) {
|
|
|
4388
4388
|
return false;
|
|
4389
4389
|
}
|
|
4390
4390
|
} else if (typeof pathsOrOptions.pathsToSkip == 'string') {
|
|
4391
|
-
if (pathsOrOptions.pathsToSkip.includes(p)) {
|
|
4391
|
+
if (pathsOrOptions.pathsToSkip.indexOf(' ') !== -1 && pathsOrOptions.pathsToSkip.split(' ').includes(p)) {
|
|
4392
|
+
return false;
|
|
4393
|
+
} else if (pathsOrOptions.pathsToSkip === p) {
|
|
4392
4394
|
return false;
|
|
4393
4395
|
}
|
|
4394
4396
|
}
|
|
@@ -429,7 +429,8 @@ SchemaDocumentArray.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
429
429
|
const path = options.path || this.path;
|
|
430
430
|
|
|
431
431
|
if (!Array.isArray(value)) {
|
|
432
|
-
|
|
432
|
+
const castNonArraysOption = this.options.castNonArrays ?? SchemaDocumentArray.options.castNonArrays;
|
|
433
|
+
if (!init && !castNonArraysOption) {
|
|
433
434
|
throw new CastError('DocumentArray', value, this.path, null, this);
|
|
434
435
|
}
|
|
435
436
|
// gh-2442 mark whole array as modified if we're initializing a doc from
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "9.12.
|
|
4
|
+
"version": "9.12.3",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"linkinator": "8.x",
|
|
50
50
|
"lodash.isequal": "4.5.0",
|
|
51
51
|
"lodash.isequalwith": "4.4.0",
|
|
52
|
-
"markdownlint-cli2": "0.24.
|
|
52
|
+
"markdownlint-cli2": "0.24.1",
|
|
53
53
|
"marked": "18.1.2",
|
|
54
54
|
"mkdirp": "^3.0.1",
|
|
55
55
|
"mocha": "12.0.3",
|
package/types/expressions.d.ts
CHANGED
|
@@ -126,7 +126,7 @@ declare module 'mongoose' {
|
|
|
126
126
|
|
|
127
127
|
export interface Round {
|
|
128
128
|
/**
|
|
129
|
-
* Rounds a number to
|
|
129
|
+
* Rounds a number to a whole integer or to a specified decimal place.
|
|
130
130
|
*
|
|
131
131
|
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/#mongodb-expression-exp.-round
|
|
132
132
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -677,6 +677,9 @@ declare module 'mongoose' {
|
|
|
677
677
|
/** Removes index by name or index spec */
|
|
678
678
|
removeIndex(index: string | AnyObject): this;
|
|
679
679
|
|
|
680
|
+
/** Removes the given virtual or virtuals from this schema. Throws if a virtual does not exist. */
|
|
681
|
+
removeVirtual(path: string | string[]): this;
|
|
682
|
+
|
|
680
683
|
/** Returns an Array of path strings that are required by this schema. */
|
|
681
684
|
requiredPaths(invalidate?: boolean): string[];
|
|
682
685
|
|