Skip to content

Commit 3f43612

Browse files
authored
Merge branch 'Automattic:master' into fix-projection-nested-objects-new
2 parents 3ff4f4d + 7cab712 commit 3f43612

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+835
-269
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
8.14.0 / 2025-04-25
2+
===================
3+
* feat: upgrade MongoDB driver -> 6.16 #15371
4+
* feat: implement Query findById methods #15337 [sderrow](https://github.com/sderrow)
5+
* feat(subdocument): support schematype-level minimize option to disable minimizing empty subdocuments #15336 #15313
6+
* feat: add skipOriginalStackTraces option to avoid stack trace performance overhead #15345 #15194
7+
* fix(model): disallow Model.findOneAndUpdate(update) and fix TypeScript types re: findOneAndUpdate #15365 #15363
8+
* types: correctly recurse in InferRawDocType #15357 #14954 [JavaScriptBach](https://github.com/JavaScriptBach)
9+
* types: include virtuals in toJSON and toObject output if virtuals: true set #15346 #15316
10+
* types: make init hooks types accurately reflect runtime behavior #15331 #15301
11+
12+
8.13.3 / 2025-04-24
13+
===================
14+
* fix: export MongooseBulkSaveIncompleteError #15370 #15369
15+
* fix: clone POJOs and arrays when casting query filter to avoid mutating objects #15367 #15364
16+
* types(connection): add Connection.prototype.bulkWrite() to types #15368 #15359
17+
* docs: add version requirements to v7 migration docs #15361 [SethFalco](https://github.com/SethFalco)
18+
* docs: update links in deleteOne & deleteMany API def #15360 [Elliot67](https://github.com/Elliot67)
19+
* docs: adds Model#count to list of fns callback removed from #15349 [SethFalco](https://github.com/SethFalco)
20+
21+
8.13.2 / 2025-04-03
22+
===================
23+
* fix: avoid double calling validators on paths in document arrays underneath subdocuments #15338 #15335
24+
25+
8.13.1 / 2025-03-28
26+
===================
27+
* fix(populate): handle virtual populate on array of UUIDs #15329 #15315
28+
* types: allow default function returning undefined with DocType override #15328
29+
30+
8.13.0 / 2025-03-24
31+
===================
32+
* feat: bump mongodb driver -> 6.15.0
33+
* feat: support custom types exported from driver #15321
34+
35+
8.12.2 / 2025-03-21
36+
===================
37+
* fix(document): avoid stripping out fields in discriminator schema after select: false field #15322 #15308
38+
* fix(AggregationCursor): make next() error if schema pre('aggregate') middleware throws error #15293 #15279
39+
* fix(populate): correctly get schematypes when deep populating under a map #15302 #9359
40+
* fix(model): avoid returning null from bulkSave() if error doesn't have writeErrors property #15323
41+
* types: add WithTimestamps utility type #15318 [baruchiro](https://github.com/baruchiro)
42+
* docs: update references to the ms module in date schema documentation #15319 [baruchiro](https://github.com/baruchiro)
43+
* docs: fix typo in schematypes.md #15305 [skyran1278](https://github.com/skyran1278)
44+
145
8.12.1 / 2025-03-04
246
===================
347
* fix: match bson version with mongodb's bson version #15297 [hasezoey](https://github.com/hasezoey)

benchmarks/findOneWithCast.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
const mongoose = require('../');
4+
5+
run().catch(err => {
6+
console.error(err);
7+
process.exit(-1);
8+
});
9+
10+
async function run() {
11+
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_benchmark');
12+
13+
const SchemaParticipant = new mongoose.Schema(
14+
{
15+
user: mongoose.Schema.Types.UUID,
16+
},
17+
{
18+
_id: false
19+
}
20+
);
21+
22+
const TestSchema = new mongoose.Schema(
23+
{
24+
participants1: { type: [SchemaParticipant] },
25+
participants2: { type: [SchemaParticipant] },
26+
participants3: { type: [SchemaParticipant] },
27+
participants4: { type: [SchemaParticipant] },
28+
participants5: { type: [SchemaParticipant] },
29+
date: { type: Number },
30+
},
31+
{
32+
collection: 'test_uuid_mutations',
33+
}
34+
);
35+
36+
const TestModel = mongoose.model('Test', TestSchema);
37+
38+
if (!process.env.MONGOOSE_BENCHMARK_SKIP_SETUP) {
39+
await TestModel.deleteMany({});
40+
}
41+
42+
const peer = {
43+
user: '1583b99d-8462-4343-8dfd-9105252e5662',
44+
};
45+
46+
const numIterations = 500;
47+
const queryStart = Date.now();
48+
for (let i = 0; i < numIterations; ++i) {
49+
for (let j = 0; j < 10; ++j) {
50+
await TestModel.findOne({
51+
$or: [
52+
{ participants1: { $elemMatch: peer } },
53+
{ participants2: { $elemMatch: peer } },
54+
{ participants3: { $elemMatch: peer } },
55+
{ participants4: { $elemMatch: peer } },
56+
{ participants5: { $elemMatch: peer } }
57+
]
58+
});
59+
}
60+
}
61+
const queryEnd = Date.now();
62+
63+
const results = {
64+
'Average findOne time ms': +((queryEnd - queryStart) / numIterations).toFixed(2)
65+
};
66+
67+
console.log(JSON.stringify(results, null, ' '));
68+
process.exit(0);
69+
}

docs/migrating_to_7.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ you should be aware of when migrating from Mongoose 6.x to Mongoose 7.x.
1111

1212
If you're still on Mongoose 5.x, please read the [Mongoose 5.x to 6.x migration guide](migrating_to_6.html) and upgrade to Mongoose 6.x first.
1313

14+
* [Version Requirements](#version-requirements)
1415
* [`strictQuery`](#strictquery)
1516
* [Removed `remove()`](#removed-remove)
1617
* [Dropped callback support](#dropped-callback-support)
@@ -28,6 +29,12 @@ If you're still on Mongoose 5.x, please read the [Mongoose 5.x to 6.x migration
2829
* [Removed `LeanDocument` and support for `extends Document`](#removed-leandocument-and-support-for-extends-document)
2930
* [New parameters for `HydratedDocument`](#new-parameters-for-hydrateddocument)
3031

32+
## Version Requirements {#version-requirements}
33+
34+
Mongoose now requires Node.js >= 14.0.0 and MongoDB Node Driver >= 5.0.0.
35+
36+
See [the MongoDB Node Driver migration guide](https://github.com/mongodb/node-mongodb-native/blob/main/etc/notes/CHANGES_5.0.0.md) for detailed info.
37+
3138
## `strictQuery` {#strictquery}
3239

3340
`strictQuery` is now false by default.
@@ -106,6 +113,7 @@ They always return promises.
106113
* `Model.aggregate`
107114
* `Model.bulkWrite`
108115
* `Model.cleanIndexes`
116+
* `Model.count`
109117
* `Model.countDocuments`
110118
* `Model.create`
111119
* `Model.createCollection`
@@ -130,6 +138,7 @@ They always return promises.
130138
* `Model.syncIndexes`
131139
* `Model.updateMany`
132140
* `Model.updateOne`
141+
* `Query.prototype.count`
133142
* `Query.prototype.find`
134143
* `Query.prototype.findOne`
135144
* `Query.prototype.findOneAndDelete`
@@ -156,7 +165,7 @@ conn.startSession(function(err, session) {
156165
// After
157166
const session = await conn.startSession();
158167
// Or:
159-
conn.startSession().then(sesson => { /* ... */ });
168+
conn.startSession().then(session => { /* ... */ });
160169

161170
// With error handling
162171
try {

0 commit comments

Comments
 (0)