Skip to content

Commit 8527c8d

Browse files
authored
Merge branch '8.0' into vkarpov15/gh-13782
2 parents 6ddbcb8 + 2348b7a commit 8527c8d

File tree

86 files changed

+734
-1286
lines changed

Some content is hidden

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

86 files changed

+734
-1286
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ module.exports = {
2222
'**/*.md/*.ts',
2323
'**/*.md/*.typescript'
2424
],
25+
parserOptions: {
26+
project: './tsconfig.json'
27+
},
2528
extends: [
2629
'plugin:@typescript-eslint/eslint-recommended',
2730
'plugin:@typescript-eslint/recommended'

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Setup node
2828
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
2929
with:
30-
node-version: 14
30+
node-version: 18
3131

3232
- run: npm install
3333

@@ -39,7 +39,7 @@ jobs:
3939
strategy:
4040
fail-fast: false
4141
matrix:
42-
node: [14, 16, 18, 20]
42+
node: [16, 18, 20]
4343
os: [ubuntu-20.04, ubuntu-22.04]
4444
mongodb: [4.4.18, 5.0.14, 6.0.4]
4545
include:
@@ -108,7 +108,7 @@ jobs:
108108
- name: Setup Deno
109109
uses: denoland/setup-deno@v1
110110
with:
111-
deno-version: v1.34.x
111+
deno-version: v1.36.x
112112
- run: deno --version
113113
- run: npm install
114114
- name: Run Deno tests

.github/workflows/tsd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Setup node
2828
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
2929
with:
30-
node-version: 14
30+
node-version: 18
3131

3232
- run: npm install
3333

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
7.5.1 / 2023-09-11
2+
==================
3+
* fix: set default value for _update when no update object is provided and versionKey is set to false #13795 #13783 [MohOraby](https://github.com/MohOraby)
4+
* fix: avoid unexpected error when accessing null array element on discriminator array when populating #13716 [ZSabakh](https://github.com/ZSabakh)
5+
* types(schematypes): use DocType for instance method this #13822 #13800 [pshaddel](https://github.com/pshaddel)
6+
* types: remove duplicated 'exists' method in Model interface in models.d.ts #13818 [ohzeno](https://github.com/ohzeno)
7+
* docs(model): replace outdated docs on deprecated findOneAndUpdate() overwrite option #13821 #13715
8+
* docs: add example of using `virtuals.pathsToSkip` option for `toObject()` and `toJSON()` #13798 [RobertHunter-Pluto](https://github.com/RobertHunter-Pluto)
9+
110
7.5.0 / 2023-08-29
211
==================
312
* feat: use mongodb driver v5.18.1

docs/middleware.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ In query middleware functions, `this` refers to the query.
4848
* [find](api/query.html#query_Query-find)
4949
* [findOne](api/query.html#query_Query-findOne)
5050
* [findOneAndDelete](api/query.html#query_Query-findOneAndDelete)
51-
* [findOneAndRemove](api/query.html#query_Query-findOneAndRemove)
5251
* [findOneAndReplace](api/query.html#query_Query-findOneAndReplace)
5352
* [findOneAndUpdate](api/query.html#query_Query-findOneAndUpdate)
5453
* [remove](api/model.html#model_Model-remove)
@@ -81,7 +80,6 @@ Here are the possible strings that can be passed to `pre()`
8180
* find
8281
* findOne
8382
* findOneAndDelete
84-
* findOneAndRemove
8583
* findOneAndReplace
8684
* findOneAndUpdate
8785
* init

docs/migrating_to_8.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Migrating from 7.x to 8.x
2+
3+
<style>
4+
ul > li {
5+
padding: 4px 0px;
6+
}
7+
</style>
8+
9+
There are several backwards-breaking changes
10+
you should be aware of when migrating from Mongoose 7.x to Mongoose 8.x.
11+
12+
If you're still on Mongoose 6.x or earlier, please read the [Mongoose 6.x to 7.x migration guide](migrating_to_7.html) and upgrade to Mongoose 7.x first before upgrading to Mongoose 8.
13+
14+
* [Removed `rawResult` option for `findOneAndUpdate()`](#removed-rawresult-option-for-findoneandupdate)
15+
* [Changed behavior for `findOneAndUpdate()` with `orFail()` and upsert](#changed-behavior-for-findoneandupdate-with-orfail-and-upsert)
16+
* [MongoDB Node Driver 6.0](#mongodb-node-driver-6)
17+
* [Removed `findOneAndRemove()`](#removed-findoneandremove)
18+
* [Removed id Setter](#removed-id-setter)
19+
20+
<h2 id="removed-rawresult-option-for-findoneandupdate"><a href="#removed-rawresult-option-for-findoneandupdate">Removed <code>rawResult</code> option for <code>findOneAndUpdate()</code></a></h2>
21+
22+
The `rawResult` option for `findOneAndUpdate()`, `findOneAndReplace()`, and `findOneAndDelete()` has been replaced by the `includeResultMetadata` option.
23+
24+
```javascript
25+
const filter = { name: 'Will Riker' };
26+
const update = { age: 29 };
27+
28+
const res = await Character.findOneAndUpdate(filter, update, {
29+
new: true,
30+
upsert: true,
31+
// Replace `rawResult: true` with `includeResultMetadata: true`
32+
includeResultMetadata: true
33+
});
34+
```
35+
36+
`includeResultMetadata` in Mongoose 8 behaves identically to `rawResult`.
37+
38+
<h2 id="changed-behavior-for-findoneandupdate-with-orfail-and-upsert"><a href="#changed-behavior-for-findoneandupdate-with-orfail-and-upsert">Changed behavior for <code>findOneAndUpdate()</code> with <code>orFail()</code> and upsert</a></h2>
39+
40+
In Mongoose 7, `findOneAndUpdate(filter, update, { upsert: true }).orFail()` would throw a `DocumentNotFoundError` if a new document was upserted.
41+
In other words, `findOneAndUpdate().orFail()` always threw an error if no document was found, even if a new document was upserted.
42+
43+
In Mongoose 8, `findOneAndUpdate(filter, update, { upsert: true }).orFail()` always succeeds.
44+
`findOneAndUpdate().orFail()` now throws a `DocumentNotFoundError` if there's no document returned, rather than if no document was found.
45+
46+
<h2 id="mongodb-node-driver-6"><a href="#mongodb-node-driver-6">MongoDB Node Driver 6</a></h2>
47+
48+
Mongoose 8 uses [v6.x of the MongoDB Node driver](https://github.com/mongodb/node-mongodb-native/blob/main/HISTORY.md#600-2023-08-28).
49+
There's a few noteable changes in MongoDB Node driver v6 that affect Mongoose:
50+
51+
1. The `ObjectId` constructor no longer accepts strings of length 12. In Mongoose 7, `new mongoose.Types.ObjectId('12charstring')` was perfectly valid. In Mongoose 8, `new mongoose.Types.ObjectId('12charstring')` throws an error.
52+
53+
<h2 id="removed-findoneandremove"><a href="#removed-findoneandremove">Removed <code>findOneAndRemove()</code></a></h2>
54+
55+
In Mongoose 7, `findOneAndRemove()` was an alias for `findOneAndDelete()` that Mongoose supported for backwards compatibility.
56+
Mongoose 8 no longer supports `findOneAndRemove()`.
57+
Use `findOneAndDelete()` instead.
58+
59+
<h2 id="removed-id-setter"><a href="#removed-id-setter">Removed id Setter</a></h2>
60+
61+
In Mongoose 7.4, Mongoose introduced an `id` setter that made `doc.id = '0'.repeat(24)` equivalent to `doc._id = '0'.repeat(24)`.
62+
In Mongoose 8, that setter is now removed.

docs/models.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ If you attempt to `save()` a document from a View, you will get an error from th
193193

194194
## Yet more
195195

196-
The [API docs](api/model.html#model_Model) cover many additional methods available like [count](api/model.html#model_Model-count), [mapReduce](api/model.html#model_Model-mapReduce), [aggregate](api/model.html#model_Model-aggregate), and [more](api/model.html#model_Model-findOneAndRemove).
196+
The [API docs](api/model.html#model_Model) cover many additional methods available like [count](api/model.html#model_Model-count), [mapReduce](api/model.html#model_Model-mapReduce), [aggregate](api/model.html#model_Model-aggregate), and more.
197197

198198
## Next Up
199199

docs/queries.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Each of these functions returns a
1414
* [`Model.findByIdAndUpdate()`](api.html#model_Model-findByIdAndUpdate)
1515
* [`Model.findOne()`](api.html#model_Model-findOne)
1616
* [`Model.findOneAndDelete()`](api.html#model_Model-findOneAndDelete)
17-
* [`Model.findOneAndRemove()`](api.html#model_Model-findOneAndRemove)
1817
* [`Model.findOneAndReplace()`](api.html#model_Model-findOneAndReplace)
1918
* [`Model.findOneAndUpdate()`](api.html#model_Model-findOneAndUpdate)
2019
* [`Model.replaceOne()`](api.html#model_Model-replaceOne)

docs/source/api.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ const files = [
1818
'lib/cursor/QueryCursor.js',
1919
'lib/aggregate.js',
2020
'lib/cursor/AggregationCursor.js',
21-
'lib/schematype.js',
22-
'lib/virtualtype.js',
21+
'lib/schemaType.js',
22+
'lib/virtualType.js',
2323
'lib/error/index.js',
2424
'lib/schema/array.js',
25-
'lib/schema/documentarray.js',
26-
'lib/schema/SubdocumentPath.js',
25+
'lib/schema/documentArray.js',
26+
'lib/schema/subdocument.js',
2727
'lib/schema/boolean.js',
2828
'lib/schema/buffer.js',
2929
'lib/schema/number.js',
30-
'lib/schema/objectid.js',
30+
'lib/schema/objectId.js',
3131
'lib/schema/string.js',
3232
'lib/options/SchemaTypeOptions.js',
3333
'lib/options/SchemaArrayOptions.js',

docs/source/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ docs['docs/migration.md'] = { guide: true, title: 'Migration Guide', markdown: t
6565
docs['docs/migrating_to_5.md'] = { guide: true, title: 'Migrating to Mongoose 5', markdown: true };
6666
docs['docs/migrating_to_6.md'] = { guide: true, title: 'Migrating to Mongoose 6', markdown: true };
6767
docs['docs/migrating_to_7.md'] = { guide: true, title: 'Migrating to Mongoose 7', markdown: true };
68+
docs['docs/migrating_to_8.md'] = { guide: true, title: 'Migrating to Mongoose 8', markdown: true };
6869
docs['docs/connections.md'] = { guide: true, title: 'Connecting to MongoDB', markdown: true };
6970
docs['docs/lambda.md'] = { guide: true, title: 'Using Mongoose With AWS Lambda', markdown: true };
7071
docs['docs/geojson.md'] = { guide: true, title: 'Using GeoJSON', acquit: true, markdown: true };

0 commit comments

Comments
 (0)