mongoose 8.19.0 → 8.19.1
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/README.md
CHANGED
|
@@ -42,10 +42,32 @@ View all 400+ [contributors](https://github.com/Automattic/mongoose/graphs/contr
|
|
|
42
42
|
|
|
43
43
|
First install [Node.js](http://nodejs.org/) and [MongoDB](https://www.mongodb.org/downloads). Then:
|
|
44
44
|
|
|
45
|
+
Then install the `mongoose` package using your preferred package manager:
|
|
46
|
+
|
|
47
|
+
### Using npm
|
|
48
|
+
|
|
45
49
|
```sh
|
|
46
50
|
npm install mongoose
|
|
47
51
|
```
|
|
48
52
|
|
|
53
|
+
### Using pnpm
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
pnpm add mongoose
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Using Yarn
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
yarn add mongoose
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Using Bun
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
bun add mongoose
|
|
69
|
+
```
|
|
70
|
+
|
|
49
71
|
Mongoose 6.8.0 also includes alpha support for [Deno](https://deno.land/).
|
|
50
72
|
|
|
51
73
|
## Importing
|
|
@@ -379,8 +379,13 @@ function walkUpdatePath(schema, obj, op, options, context, filter, prefix) {
|
|
|
379
379
|
(utils.isObject(val) && Object.keys(val).length === 0);
|
|
380
380
|
}
|
|
381
381
|
} else {
|
|
382
|
-
const
|
|
383
|
-
|
|
382
|
+
const isModifier = (key === '$each' || key === '$or' || key === '$and' || key === '$in');
|
|
383
|
+
if (isModifier && !prefix) {
|
|
384
|
+
throw new MongooseError('Invalid update: Unexpected modifier "' + key + '" as a key in operator. '
|
|
385
|
+
+ 'Did you mean something like { $addToSet: { fieldName: { $each: [...] } } }? '
|
|
386
|
+
+ 'Modifiers such as "$each", "$or", "$and", "$in" must appear under a valid field path.');
|
|
387
|
+
}
|
|
388
|
+
const checkPath = isModifier ? prefix : prefix + key;
|
|
384
389
|
schematype = schema._getSchema(checkPath);
|
|
385
390
|
|
|
386
391
|
// You can use `$setOnInsert` with immutable keys
|
|
@@ -7,6 +7,9 @@ const updatedPathsByArrayFilter = require('./updatedPathsByArrayFilter');
|
|
|
7
7
|
|
|
8
8
|
module.exports = function castArrayFilters(query) {
|
|
9
9
|
const arrayFilters = query.options.arrayFilters;
|
|
10
|
+
if (!Array.isArray(arrayFilters)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
10
13
|
const update = query.getUpdate();
|
|
11
14
|
const schema = query.schema;
|
|
12
15
|
const updatedPathsByFilter = updatedPathsByArrayFilter(update);
|
|
@@ -29,10 +32,6 @@ module.exports = function castArrayFilters(query) {
|
|
|
29
32
|
};
|
|
30
33
|
|
|
31
34
|
function _castArrayFilters(arrayFilters, schema, strictQuery, updatedPathsByFilter, query) {
|
|
32
|
-
if (!Array.isArray(arrayFilters)) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
35
|
// Map to store discriminator values for embedded documents in the array filters.
|
|
37
36
|
// This is used to handle cases where array filters target specific embedded document types.
|
|
38
37
|
const discriminatorValueMap = {};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const modifiedPaths = require('./modifiedPaths');
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Decorate the update with a version key, if necessary
|
|
7
5
|
* @api private
|
|
@@ -12,15 +10,26 @@ module.exports = function decorateUpdateWithVersionKey(update, options, versionK
|
|
|
12
10
|
return;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (options.overwrite) {
|
|
13
|
+
if (options.overwrite) {
|
|
14
|
+
if (!hasKey(update, versionKey)) {
|
|
18
15
|
update[versionKey] = 0;
|
|
19
|
-
} else {
|
|
20
|
-
if (!update.$setOnInsert) {
|
|
21
|
-
update.$setOnInsert = {};
|
|
22
|
-
}
|
|
23
|
-
update.$setOnInsert[versionKey] = 0;
|
|
24
16
|
}
|
|
17
|
+
} else if (
|
|
18
|
+
!hasKey(update, versionKey) &&
|
|
19
|
+
!hasKey(update?.$set, versionKey) &&
|
|
20
|
+
!hasKey(update?.$inc, versionKey) &&
|
|
21
|
+
!hasKey(update?.$setOnInsert, versionKey)
|
|
22
|
+
) {
|
|
23
|
+
if (!update.$setOnInsert) {
|
|
24
|
+
update.$setOnInsert = {};
|
|
25
|
+
}
|
|
26
|
+
update.$setOnInsert[versionKey] = 0;
|
|
25
27
|
}
|
|
26
28
|
};
|
|
29
|
+
|
|
30
|
+
function hasKey(obj, key) {
|
|
31
|
+
if (obj == null || typeof obj !== 'object') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "8.19.
|
|
4
|
+
"version": "8.19.1",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@ark/attest": "0.48.2",
|
|
33
|
-
"@babel/core": "7.28.
|
|
33
|
+
"@babel/core": "7.28.4",
|
|
34
34
|
"@babel/preset-env": "7.28.3",
|
|
35
35
|
"@mongodb-js/mongodb-downloader": "^0.4.2",
|
|
36
36
|
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"markdownlint-cli2": "^0.18.1",
|
|
58
58
|
"marked": "15.0.12",
|
|
59
59
|
"mkdirp": "^3.0.1",
|
|
60
|
-
"mocha": "11.7.
|
|
60
|
+
"mocha": "11.7.4",
|
|
61
61
|
"moment": "2.30.1",
|
|
62
|
-
"mongodb-memory-server": "10.2.
|
|
62
|
+
"mongodb-memory-server": "10.2.1",
|
|
63
63
|
"mongodb-runner": "^5.8.2",
|
|
64
64
|
"ncp": "^2.0.0",
|
|
65
65
|
"nyc": "15.1.0",
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"sinon": "21.0.0",
|
|
69
69
|
"stream-browserify": "3.0.0",
|
|
70
70
|
"tsd": "0.33.0",
|
|
71
|
-
"typescript": "5.9.
|
|
71
|
+
"typescript": "5.9.3",
|
|
72
72
|
"uuid": "11.1.0",
|
|
73
|
-
"webpack": "5.
|
|
73
|
+
"webpack": "5.102.0"
|
|
74
74
|
},
|
|
75
75
|
"directories": {
|
|
76
76
|
"lib": "./lib/mongoose"
|
package/types/query.d.ts
CHANGED
|
@@ -10,11 +10,9 @@ declare module 'mongoose' {
|
|
|
10
10
|
* { age: { $gte: 30 } }
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
|
-
type RootFilterQuery<T> = FilterQuery<T> | Query<any, any> | Types.ObjectId;
|
|
13
|
+
type RootFilterQuery<T> = IsItRecordAndNotAny<T> extends true ? FilterQuery<T> | Query<any, any> | Types.ObjectId : FilterQuery<Record<string, any>> | Query<any, any> | Types.ObjectId;
|
|
14
14
|
|
|
15
|
-
type FilterQuery<T> =
|
|
16
|
-
({ [P in keyof T]?: Condition<T[P]>; } & RootQuerySelector<T> & { _id?: Condition<string>; }) :
|
|
17
|
-
FilterQuery<Record<string, any>>;
|
|
15
|
+
type FilterQuery<T> = ({ [P in keyof T]?: Condition<T[P]>; } & RootQuerySelector<T> & { _id?: Condition<string>; });
|
|
18
16
|
|
|
19
17
|
type MongooseBaseQueryOptionKeys =
|
|
20
18
|
| 'context'
|
|
@@ -424,18 +422,10 @@ declare module 'mongoose' {
|
|
|
424
422
|
|
|
425
423
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
426
424
|
find(
|
|
427
|
-
filter
|
|
425
|
+
filter?: RootFilterQuery<RawDocType>,
|
|
428
426
|
projection?: ProjectionType<RawDocType> | null,
|
|
429
427
|
options?: QueryOptions<RawDocType> | null
|
|
430
428
|
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
|
|
431
|
-
find(
|
|
432
|
-
filter: RootFilterQuery<RawDocType>,
|
|
433
|
-
projection?: ProjectionType<RawDocType> | null
|
|
434
|
-
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
|
|
435
|
-
find(
|
|
436
|
-
filter: RootFilterQuery<RawDocType>
|
|
437
|
-
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
|
|
438
|
-
find(): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find', TDocOverrides>;
|
|
439
429
|
|
|
440
430
|
/** Declares the query a findOne operation. When executed, returns the first found document. */
|
|
441
431
|
findOne(
|
|
@@ -443,13 +433,6 @@ declare module 'mongoose' {
|
|
|
443
433
|
projection?: ProjectionType<RawDocType> | null,
|
|
444
434
|
options?: QueryOptions<RawDocType> | null
|
|
445
435
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
446
|
-
findOne(
|
|
447
|
-
filter?: RootFilterQuery<RawDocType>,
|
|
448
|
-
projection?: ProjectionType<RawDocType> | null
|
|
449
|
-
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
450
|
-
findOne(
|
|
451
|
-
filter?: RootFilterQuery<RawDocType>
|
|
452
|
-
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
453
436
|
|
|
454
437
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
455
438
|
findOneAndDelete(
|
|
@@ -484,13 +467,6 @@ declare module 'mongoose' {
|
|
|
484
467
|
projection?: ProjectionType<RawDocType> | null,
|
|
485
468
|
options?: QueryOptions<RawDocType> | null
|
|
486
469
|
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
487
|
-
findById(
|
|
488
|
-
id: mongodb.ObjectId | any,
|
|
489
|
-
projection?: ProjectionType<RawDocType> | null
|
|
490
|
-
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
491
|
-
findById(
|
|
492
|
-
id: mongodb.ObjectId | any
|
|
493
|
-
): QueryWithHelpers<DocType | null, DocType, THelpers, RawDocType, 'findOne', TDocOverrides>;
|
|
494
470
|
|
|
495
471
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
496
472
|
findByIdAndDelete(
|