Skip to content

Commit b739793

Browse files
committed
Merge branch 'master' into csfle
2 parents 2fc58da + bb59d94 commit b739793

22 files changed

+278
-55
lines changed

.github/workflows/benchmark.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ permissions:
1919

2020
jobs:
2121
typescript:
22-
runs-on: ubuntu-20.04
22+
runs-on: ubuntu-22.04
2323
name: Benchmark TypeScript Types
2424
steps:
2525
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2626
with:
2727
fetch-depth: 0
2828
- name: Setup node
29-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
29+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
3030
with:
3131
node-version: 22
3232

.github/workflows/documentation.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3232

3333
- name: Setup node
34-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
34+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
3535
with:
3636
node-version: 22
3737

@@ -45,28 +45,28 @@ jobs:
4545
# run: npm run lint-js
4646

4747
test-documentation:
48-
runs-on: ubuntu-20.04
48+
runs-on: ubuntu-22.04
4949
name: Test Generating Docs
5050
steps:
5151
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5252
- run: git fetch --depth=1 --tags # download all tags for documentation
5353

5454
- name: Setup node
55-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
55+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
5656
with:
5757
node-version: 22
5858

5959
- run: npm install
6060
- name: Setup MongoDB
6161
run: |
62-
wget -q https://downloads.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-5.0.14.tgz
63-
tar xf mongodb-linux-x86_64-ubuntu2004-5.0.14.tgz
62+
wget -q https://downloads.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-6.0.20.tgz
63+
tar xf mongodb-linux-x86_64-ubuntu2204-6.0.20.tgz
6464
mkdir -p ./data/db/27017 ./data/db/27000
6565
printf "\n--timeout 8000" >> ./test/mocha.opts
66-
./mongodb-linux-x86_64-ubuntu2004-5.0.14/bin/mongod --setParameter ttlMonitorSleepSecs=1 --fork --dbpath ./data/db/27017 --syslog --port 27017
66+
./mongodb-linux-x86_64-ubuntu2204-6.0.20/bin/mongod --setParameter ttlMonitorSleepSecs=1 --fork --dbpath ./data/db/27017 --syslog --port 27017
6767
sleep 2
68-
mongod --version
69-
echo `pwd`/mongodb-linux-x86_64-ubuntu2004-5.0.14/bin >> $GITHUB_PATH
68+
./mongodb-linux-x86_64-ubuntu2204-6.0.20/bin/mongod --version
69+
echo `pwd`/mongodb-linux-x86_64-ubuntu2204-6.0.20/bin >> $GITHUB_PATH
7070
- name: Setup config
7171
run: |
7272
echo "module.exports = {uri:'mongodb://127.0.0.1:27017/mongoose_test'};" > ./.config.js

.github/workflows/encryption-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
steps:
2727
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2828
- name: Setup node
29-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
29+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
3030
with:
3131
node-version: 22
3232
- name: Install Dependencies

.github/workflows/test.yml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2626

2727
- name: Setup node
28-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
28+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
2929
with:
3030
node-version: 22
3131

@@ -40,18 +40,13 @@ jobs:
4040
fail-fast: false
4141
matrix:
4242
node: [16, 18, 20, 22]
43-
os: [ubuntu-20.04, ubuntu-22.04]
44-
mongodb: [4.4.29, 5.0.26, 6.0.15, 7.0.12, 8.0.0]
43+
os: [ubuntu-22.04, ubuntu-24.04]
44+
mongodb: [6.0.15, 7.0.12, 8.0.0]
4545
include:
46-
- os: ubuntu-20.04 # customize on which matrix the coverage will be collected on
47-
mongodb: 5.0.26
48-
node: 16
46+
- os: ubuntu-22.04 # customize on which matrix the coverage will be collected on
47+
mongodb: 6.0.15
48+
node: 22
4949
coverage: true
50-
exclude:
51-
- os: ubuntu-22.04 # exclude because there are no 4.x mongodb builds for 2204
52-
mongodb: 4.4.29
53-
- os: ubuntu-22.04 # exclude because there are no 5.x mongodb builds for 2204
54-
mongodb: 5.0.26
5550
name: Node ${{ matrix.node }} MongoDB ${{ matrix.mongodb }} OS ${{ matrix.os }}
5651
env:
5752
MONGOMS_VERSION: ${{ matrix.mongodb }}
@@ -61,7 +56,7 @@ jobs:
6156
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6257

6358
- name: Setup node
64-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
59+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
6560
with:
6661
node-version: ${{ matrix.node }}
6762

@@ -87,7 +82,7 @@ jobs:
8782
path: coverage
8883

8984
test-deno:
90-
runs-on: ubuntu-20.04
85+
runs-on: ubuntu-22.04
9186
name: Deno tests
9287
env:
9388
MONGOMS_VERSION: 6.0.15
@@ -96,7 +91,7 @@ jobs:
9691
steps:
9792
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
9893
- name: Setup node
99-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
94+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
10095
with:
10196
node-version: 22
10297
- name: Load MongoDB binary cache
@@ -117,14 +112,14 @@ jobs:
117112
test-replica-sets:
118113
needs:
119114
- test
120-
runs-on: ubuntu-20.04
115+
runs-on: ubuntu-22.04
121116
name: Replica Set tests
122117
env:
123118
FORCE_COLOR: true
124119
steps:
125120
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
126121
- name: Setup node
127-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
122+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
128123
with:
129124
node-version: 22
130125
- run: npm install

.github/workflows/tidelift-alignment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1919
- name: Setup node
20-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
20+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
2121
with:
2222
node-version: 22
2323
- name: Alignment

.github/workflows/tsd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2424

2525
- name: Setup node
26-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
26+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
2727
with:
2828
node-version: 22
2929

@@ -41,7 +41,7 @@ jobs:
4141
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4242

4343
- name: Setup node
44-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
44+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
4545
with:
4646
node-version: 22
4747

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
8.13.2 / 2025-04-03
2+
===================
3+
* fix: avoid double calling validators on paths in document arrays underneath subdocuments #15338 #15335
4+
5+
8.13.1 / 2025-03-28
6+
===================
7+
* fix(populate): handle virtual populate on array of UUIDs #15329 #15315
8+
* types: allow default function returning undefined with DocType override #15328
9+
10+
8.13.0 / 2025-03-24
11+
===================
12+
* feat: bump mongodb driver -> 6.15.0
13+
* feat: support custom types exported from driver #15321
14+
15+
8.12.2 / 2025-03-21
16+
===================
17+
* fix(document): avoid stripping out fields in discriminator schema after select: false field #15322 #15308
18+
* fix(AggregationCursor): make next() error if schema pre('aggregate') middleware throws error #15293 #15279
19+
* fix(populate): correctly get schematypes when deep populating under a map #15302 #9359
20+
* fix(model): avoid returning null from bulkSave() if error doesn't have writeErrors property #15323
21+
* types: add WithTimestamps utility type #15318 [baruchiro](https://github.com/baruchiro)
22+
* docs: update references to the ms module in date schema documentation #15319 [baruchiro](https://github.com/baruchiro)
23+
* docs: fix typo in schematypes.md #15305 [skyran1278](https://github.com/skyran1278)
24+
125
8.12.1 / 2025-03-04
226
===================
327
* fix: match bson version with mongodb's bson version #15297 [hasezoey](https://github.com/hasezoey)

docs/migrating_to_7.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ They always return promises.
106106
* `Model.aggregate`
107107
* `Model.bulkWrite`
108108
* `Model.cleanIndexes`
109+
* `Model.count`
109110
* `Model.countDocuments`
110111
* `Model.create`
111112
* `Model.createCollection`
@@ -130,6 +131,7 @@ They always return promises.
130131
* `Model.syncIndexes`
131132
* `Model.updateMany`
132133
* `Model.updateOne`
134+
* `Query.prototype.count`
133135
* `Query.prototype.find`
134136
* `Query.prototype.findOne`
135137
* `Query.prototype.findOneAndDelete`
@@ -156,7 +158,7 @@ conn.startSession(function(err, session) {
156158
// After
157159
const session = await conn.startSession();
158160
// Or:
159-
conn.startSession().then(sesson => { /* ... */ });
161+
conn.startSession().then(session => { /* ... */ });
160162

161163
// With error handling
162164
try {

lib/document.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -747,16 +747,16 @@ function init(self, obj, doc, opts, prefix) {
747747
for (let index = 0; index < len; ++index) {
748748
i = keys[index];
749749
// avoid prototype pollution
750-
if (i === '__proto__' || i === 'constructor') {
751-
return;
750+
if (specialProperties.has(i)) {
751+
continue;
752752
}
753753
path = prefix ? prefix + i : i;
754754
schemaType = docSchema.path(path);
755755
// Should still work if not a model-level discriminator, but should not be
756756
// necessary. This is *only* to catch the case where we queried using the
757757
// base model and the discriminated model has a projection
758758
if (docSchema.$isRootDiscriminator && !self.$__isSelected(path)) {
759-
return;
759+
continue;
760760
}
761761

762762
const value = obj[i];
@@ -1720,7 +1720,7 @@ Document.prototype.$__set = function(pathToMark, path, options, constructing, pa
17201720
const last = next === l;
17211721
cur += (cur ? '.' + parts[i] : parts[i]);
17221722
if (specialProperties.has(parts[i])) {
1723-
return;
1723+
continue;
17241724
}
17251725

17261726
if (last) {
@@ -2721,12 +2721,33 @@ function _getPathsToValidate(doc, pathsToValidate, pathsToSkip, isNestedValidate
27212721
function addToPaths(p) { paths.add(p); }
27222722

27232723
if (!isNestedValidate) {
2724-
// If we're validating a subdocument, all this logic will run anyway on the top-level document, so skip for subdocuments
2725-
const subdocs = doc.$getAllSubdocs({ useCache: true });
2724+
// If we're validating a subdocument, all this logic will run anyway on the top-level document, so skip for subdocuments.
2725+
// But only run for top-level subdocuments, because we're looking for subdocuments that are not modified at top-level but
2726+
// have a modified path. If that is the case, we will run validation on the top-level subdocument, and via that run validation
2727+
// on any subdocuments down to the modified path.
2728+
const topLevelSubdocs = [];
2729+
for (const path of Object.keys(doc.$__schema.paths)) {
2730+
const schemaType = doc.$__schema.path(path);
2731+
if (schemaType.$isSingleNested) {
2732+
const subdoc = doc.$get(path);
2733+
if (subdoc) {
2734+
topLevelSubdocs.push(subdoc);
2735+
}
2736+
} else if (schemaType.$isMongooseDocumentArray) {
2737+
const arr = doc.$get(path);
2738+
if (arr && arr.length) {
2739+
for (const subdoc of arr) {
2740+
if (subdoc) {
2741+
topLevelSubdocs.push(subdoc);
2742+
}
2743+
}
2744+
}
2745+
}
2746+
}
27262747
const modifiedPaths = doc.modifiedPaths();
2727-
for (const subdoc of subdocs) {
2748+
for (const subdoc of topLevelSubdocs) {
27282749
if (subdoc.$basePath) {
2729-
const fullPathToSubdoc = subdoc.$isSingleNested ? subdoc.$__pathRelativeToParent() : subdoc.$__fullPathWithIndexes();
2750+
const fullPathToSubdoc = subdoc.$__pathRelativeToParent();
27302751

27312752
// Remove child paths for now, because we'll be validating the whole
27322753
// subdoc.
@@ -2736,11 +2757,12 @@ function _getPathsToValidate(doc, pathsToValidate, pathsToSkip, isNestedValidate
27362757
paths.delete(fullPathToSubdoc + '.' + modifiedPath);
27372758
}
27382759

2760+
const subdocParent = subdoc.$parent();
27392761
if (doc.$isModified(fullPathToSubdoc, null, modifiedPaths) &&
27402762
// Avoid using isDirectModified() here because that does additional checks on whether the parent path
27412763
// is direct modified, which can cause performance issues re: gh-14897
2742-
!doc.$__.activePaths.getStatePaths('modify').hasOwnProperty(fullPathToSubdoc) &&
2743-
!doc.$isDefault(fullPathToSubdoc)) {
2764+
!subdocParent.$__.activePaths.getStatePaths('modify').hasOwnProperty(fullPathToSubdoc) &&
2765+
!subdocParent.$isDefault(fullPathToSubdoc)) {
27442766
paths.add(fullPathToSubdoc);
27452767

27462768
if (doc.$__.pathsToScopes == null) {

lib/helpers/populate/assignRawDocsToIdStructure.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ function assignRawDocsToIdStructure(rawIds, resultDocs, resultOrder, options, re
7878
continue;
7979
}
8080

81-
sid = String(id);
81+
if (id?.constructor?.name === 'Binary' && id.sub_type === 4 && typeof id.toUUID === 'function') {
82+
// Workaround for gh-15315 because Mongoose UUIDs don't use BSON UUIDs yet.
83+
sid = String(id.toUUID());
84+
} else {
85+
sid = String(id);
86+
}
8287
doc = resultDocs[sid];
8388
// If user wants separate copies of same doc, use this option
8489
if (options.clone && doc != null) {

0 commit comments

Comments
 (0)