Skip to content

Commit 5ba0ae5

Browse files
committed
Merge branch 'master' into gh-pages
2 parents 1246eb1 + 2dda096 commit 5ba0ae5

28 files changed

+295
-294
lines changed

.eslintrc.js

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = {
77
ignorePatterns: [
88
'tools',
99
'dist',
10-
'website.js',
1110
'test/files/*',
1211
'benchmarks',
1312
'*.min.js',

.github/workflows/documentation.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- 'website.js'
1111
- 'CHANGELOG.md'
1212
push:
13-
branches:ubuntu
13+
branches:
1414
- master
1515
paths:
1616
- '.github/workflows/documentation.yml'

.github/workflows/test.yml

+1-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
strategy:
4040
fail-fast: false
4141
matrix:
42-
node: [16, 18, 20, 22]
42+
node: [16, 18, 20, 22, 24]
4343
os: [ubuntu-22.04, ubuntu-24.04]
4444
mongodb: [6.0.15, 7.0.12, 8.0.0]
4545
include:
@@ -87,11 +87,7 @@ jobs:
8787
- name: Setup node
8888
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
8989
with:
90-
<<<<<<< HEAD
9190
node-version: 22
92-
=======
93-
node-version: 20
94-
>>>>>>> 7.x
9591
- name: Load MongoDB binary cache
9692
id: cache-mongodb-binaries
9793
uses: actions/cache@v4
@@ -119,11 +115,7 @@ jobs:
119115
- name: Setup node
120116
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
121117
with:
122-
<<<<<<< HEAD
123118
node-version: 22
124-
=======
125-
node-version: 20
126-
>>>>>>> 7.x
127119
- run: npm install
128120
- name: Test
129121
run: npm run test-rs

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ package-lock.json
5959
# yarn package-lock
6060
yarn.lock
6161

62+
# deno lock
63+
deno.lock
64+
6265
# npm pack output
6366
mongoose.tgz
6467
mongoose-*.tgz

CHANGELOG.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
8.14.2 / 2025-05-08
2+
===================
3+
* fix(query): handle casting array filter paths underneath array filter paths with embedded discriminators #15388 #15386
4+
* docs(typescript): correct schema and model generic params in TS virtuals docs #15391
5+
* docs+types(schema): add alternative optimisticConcurrency syntaxes to docs + types #15405 #10591
6+
* chore: add Node 24 to CI matrix #15408 [stscoundrel](https://github.com/stscoundrel)
7+
18
7.8.7 / 2025-04-30
29
==================
3-
* types(aggregate): allow calling project() with a string #15304 #15300
4-
* docs: update deleteOne & deleteMany API def #15360 [Elliot67](https://github.com/Elliot67) [SethFalco](https://github.com/SethFalco)
10+
* types(aggregate): allow calling project() with a string #15304 #15300
11+
* docs: update deleteOne & deleteMany API def #15360 [Elliot67](https://github.com/Elliot67) [SethFalco](https://github.com/SethFalco)
512

613
8.14.1 / 2025-04-29
714
===================

docs/layout.pug

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ html(lang='en')
114114
a.pure-menu-link(href=`${versions.versionedPath}/docs/typescript/query-helpers.html`, class=outputUrl === `${versions.versionedPath}/docs/typescript/query-helpers.html` ? 'selected' : '') Query Helpers
115115
li.pure-menu-item.sub-item
116116
a.pure-menu-link(href=`${versions.versionedPath}/docs/typescript/populate.html`, class=outputUrl === `${versions.versionedPath}/docs/typescript/populate.html` ? 'selected' : '') Populate
117+
li.pure-menu-item.sub-item
118+
a.pure-menu-link(href=`${versions.versionedPath}/docs/typescript/virtuals.html`, class=outputUrl === `${versions.versionedPath}/docs/typescript/virtuals.html` ? 'selected' : '') Virtuals
117119
li.pure-menu-item.sub-item
118120
a.pure-menu-link(href=`${versions.versionedPath}/docs/typescript/subdocuments.html`, class=outputUrl === `${versions.versionedPath}/docs/typescript/subdocuments.html` ? 'selected' : '') Subdocuments
119121
li.pure-menu-item

docs/typescript/virtuals.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ interface UserVirtuals {
7272
fullName: string;
7373
}
7474

75-
type UserModel = Model<UserDoc, {}, UserVirtuals>; // <-- add virtuals here...
75+
type UserModel = Model<UserDoc, {}, {}, UserVirtuals>; // <-- add virtuals here...
7676

77-
const schema = new Schema<UserDoc, UserModel, UserVirtuals>({ // <-- and here
77+
const schema = new Schema<UserDoc, UserModel, {}, {}, UserVirtuals>({ // <-- and here
7878
firstName: String,
7979
lastName: String
8080
});

lib/helpers/query/getEmbeddedDiscriminatorPath.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const updatedPathsByArrayFilter = require('../update/updatedPathsByArrayFilter')
1717
*/
1818

1919
module.exports = function getEmbeddedDiscriminatorPath(schema, update, filter, path, options) {
20-
const parts = path.split('.');
20+
const parts = path.indexOf('.') === -1 ? [path] : path.split('.');
2121
let schematype = null;
2222
let type = 'adhocOrUndefined';
2323

@@ -26,9 +26,10 @@ module.exports = function getEmbeddedDiscriminatorPath(schema, update, filter, p
2626
const arrayFilters = options != null && Array.isArray(options.arrayFilters) ?
2727
options.arrayFilters : [];
2828
const updatedPathsByFilter = updatedPathsByArrayFilter(update);
29+
let startIndex = 0;
2930

3031
for (let i = 0; i < parts.length; ++i) {
31-
const originalSubpath = parts.slice(0, i + 1).join('.');
32+
const originalSubpath = parts.slice(startIndex, i + 1).join('.');
3233
const subpath = cleanPositionalOperators(originalSubpath);
3334
schematype = schema.path(subpath);
3435
if (schematype == null) {
@@ -89,6 +90,8 @@ module.exports = function getEmbeddedDiscriminatorPath(schema, update, filter, p
8990

9091
const rest = parts.slice(i + 1).join('.');
9192
schematype = discriminatorSchema.path(rest);
93+
schema = discriminatorSchema;
94+
startIndex = i + 1;
9295
if (schematype != null) {
9396
type = discriminatorSchema._getPathType(rest);
9497
break;

lib/helpers/schema/getPath.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const numberRE = /^\d+$/;
88
* @api private
99
*/
1010

11-
module.exports = function getPath(schema, path) {
11+
module.exports = function getPath(schema, path, discriminatorValueMap) {
1212
let schematype = schema.path(path);
1313
if (schematype != null) {
1414
return schematype;
@@ -26,10 +26,13 @@ module.exports = function getPath(schema, path) {
2626
schematype = schema.path(cur);
2727
if (schematype != null && schematype.schema) {
2828
schema = schematype.schema;
29-
cur = '';
3029
if (!isArray && schematype.$isMongooseDocumentArray) {
3130
isArray = true;
3231
}
32+
if (discriminatorValueMap && discriminatorValueMap[cur]) {
33+
schema = schema.discriminators[discriminatorValueMap[cur]] ?? schema;
34+
}
35+
cur = '';
3336
}
3437
}
3538

lib/helpers/update/castArrayFilters.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ function _castArrayFilters(arrayFilters, schema, strictQuery, updatedPathsByFilt
3333
return;
3434
}
3535

36+
// Map to store discriminator values for embedded documents in the array filters.
37+
// This is used to handle cases where array filters target specific embedded document types.
38+
const discriminatorValueMap = {};
39+
3640
for (const filter of arrayFilters) {
3741
if (filter == null) {
3842
throw new Error(`Got null array filter in ${arrayFilters}`);
@@ -58,12 +62,13 @@ function _castArrayFilters(arrayFilters, schema, strictQuery, updatedPathsByFilt
5862
updatedPathsByFilter[filterWildcardPath]
5963
);
6064

61-
const baseSchematype = getPath(schema, baseFilterPath);
65+
const baseSchematype = getPath(schema, baseFilterPath, discriminatorValueMap);
6266
let filterBaseSchema = baseSchematype != null ? baseSchematype.schema : null;
6367
if (filterBaseSchema != null &&
6468
filterBaseSchema.discriminators != null &&
6569
filter[filterWildcardPath + '.' + filterBaseSchema.options.discriminatorKey]) {
6670
filterBaseSchema = filterBaseSchema.discriminators[filter[filterWildcardPath + '.' + filterBaseSchema.options.discriminatorKey]] || filterBaseSchema;
71+
discriminatorValueMap[baseFilterPath] = filter[filterWildcardPath + '.' + filterBaseSchema.options.discriminatorKey];
6772
}
6873

6974
for (const key of keys) {
@@ -83,7 +88,7 @@ function _castArrayFilters(arrayFilters, schema, strictQuery, updatedPathsByFilt
8388
// If there are multiple array filters in the path being updated, make sure
8489
// to replace them so we can get the schema path.
8590
filterPathRelativeToBase = cleanPositionalOperators(filterPathRelativeToBase);
86-
schematype = getPath(filterBaseSchema, filterPathRelativeToBase);
91+
schematype = getPath(filterBaseSchema, filterPathRelativeToBase, discriminatorValueMap);
8792
}
8893

8994
if (schematype == null) {

lib/schema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const numberRE = /^\d+$/;
7777
* - [validateBeforeSave](https://mongoosejs.com/docs/guide.html#validateBeforeSave) - bool - defaults to `true`
7878
* - [validateModifiedOnly](https://mongoosejs.com/docs/api/document.html#Document.prototype.validate()) - bool - defaults to `false`
7979
* - [versionKey](https://mongoosejs.com/docs/guide.html#versionKey): string or object - defaults to "__v"
80-
* - [optimisticConcurrency](https://mongoosejs.com/docs/guide.html#optimisticConcurrency): bool - defaults to false. Set to true to enable [optimistic concurrency](https://thecodebarbarian.com/whats-new-in-mongoose-5-10-optimistic-concurrency.html).
80+
* - [optimisticConcurrency](https://mongoosejs.com/docs/guide.html#optimisticConcurrency): bool or string[] or { exclude: string[] } - defaults to false. Set to true to enable [optimistic concurrency](https://thecodebarbarian.com/whats-new-in-mongoose-5-10-optimistic-concurrency.html). Set to string array to enable optimistic concurrency for only certain fields, or `{ exclude: string[] }` to define a list of fields to ignore for optimistic concurrency.
8181
* - [collation](https://mongoosejs.com/docs/guide.html#collation): object - defaults to null (which means use no collation)
8282
* - [timeseries](https://mongoosejs.com/docs/guide.html#timeseries): object - defaults to null (which means this schema's collection won't be a timeseries collection)
8383
* - [selectPopulatedPaths](https://mongoosejs.com/docs/guide.html#selectPopulatedPaths): boolean - defaults to `true`

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mongoose",
33
"description": "Mongoose MongoDB ODM",
4-
"version": "8.14.1",
4+
"version": "8.14.2",
55
"author": "Guillermo Rauch <[email protected]>",
66
"keywords": [
77
"mongodb",
@@ -29,8 +29,8 @@
2929
"sift": "17.1.3"
3030
},
3131
"devDependencies": {
32-
"@babel/core": "7.26.10",
33-
"@babel/preset-env": "7.26.9",
32+
"@babel/core": "7.27.1",
33+
"@babel/preset-env": "7.27.1",
3434
"@typescript-eslint/eslint-plugin": "^8.19.1",
3535
"@typescript-eslint/parser": "^8.19.1",
3636
"acquit": "1.3.0",
@@ -53,9 +53,9 @@
5353
"lodash.isequal": "4.5.0",
5454
"lodash.isequalwith": "4.4.0",
5555
"markdownlint-cli2": "^0.17.1",
56-
"marked": "15.0.7",
56+
"marked": "15.0.11",
5757
"mkdirp": "^3.0.1",
58-
"mocha": "11.1.0",
58+
"mocha": "11.2.2",
5959
"moment": "2.30.1",
6060
"mongodb-memory-server": "10.1.4",
6161
"ncp": "^2.0.0",
@@ -64,10 +64,10 @@
6464
"q": "1.5.1",
6565
"sinon": "20.0.0",
6666
"stream-browserify": "3.0.0",
67-
"tsd": "0.31.2",
68-
"typescript": "5.7.3",
67+
"tsd": "0.32.0",
68+
"typescript": "5.8.3",
6969
"uuid": "11.1.0",
70-
"webpack": "5.98.0"
70+
"webpack": "5.99.7"
7171
},
7272
"directories": {
7373
"lib": "./lib/mongoose"
@@ -101,7 +101,7 @@
101101
"mongo": "node ./tools/repl.js",
102102
"publish-7x": "npm publish --tag 7x",
103103
"test": "mocha --exit ./test/*.test.js",
104-
"test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys --allow-write ./test/deno.js",
104+
"test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys --allow-write ./test/deno.mjs",
105105
"test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js",
106106
"test-tsd": "node ./test/types/check-types-filename && tsd",
107107
"setup-test-encryption": "bash scripts/configure-cluster-with-encryption.sh",

0 commit comments

Comments
 (0)