Skip to content

Commit

Permalink
Merge branch '8.0' into vkarpov15/gh-4292
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Sep 26, 2023
2 parents 8d6d31c + d5e9176 commit 8c3168f
Show file tree
Hide file tree
Showing 123 changed files with 2,166 additions and 1,496 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ module.exports = {
'**/*.md/*.ts',
'**/*.md/*.typescript'
],
parserOptions: {
project: './tsconfig.json'
},
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
runs-on: ubuntu-20.04
name: Benchmark TypeScript Types
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 16

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
runs-on: ubuntu-latest
name: Lint Markdown files
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 16

Expand All @@ -48,11 +48,11 @@ jobs:
runs-on: ubuntu-20.04
name: Test Generating Docs
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- run: git fetch --depth=1 --tags # download all tags for documentation

- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 16

Expand Down
28 changes: 16 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
runs-on: ubuntu-latest
name: Lint JS-Files
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 14
node-version: 18

- run: npm install

Expand All @@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [14, 16, 18]
node: [16, 18, 20]
os: [ubuntu-20.04, ubuntu-22.04]
mongodb: [4.4.18, 5.0.14, 6.0.4]
include:
Expand All @@ -56,11 +56,12 @@ jobs:
env:
MONGOMS_VERSION: ${{ matrix.mongodb }}
MONGOMS_PREFER_GLOBAL_PATH: 1
FORCE_COLOR: true
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: ${{ matrix.node }}

Expand Down Expand Up @@ -91,10 +92,11 @@ jobs:
env:
MONGOMS_VERSION: 6.0.4
MONGOMS_PREFER_GLOBAL_PATH: 1
FORCE_COLOR: true
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 16
- name: Load MongoDB binary cache
Expand All @@ -106,7 +108,7 @@ jobs:
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.34.x
deno-version: v1.36.x
- run: deno --version
- run: npm install
- name: Run Deno tests
Expand All @@ -117,10 +119,12 @@ jobs:
- test
runs-on: ubuntu-latest
name: Replica Set tests
env:
FORCE_COLOR: true
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 16
- run: npm install
Expand All @@ -135,6 +139,6 @@ jobs:
contents: read
steps:
- name: Check out repo
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Dependency review
uses: actions/dependency-review-action@v3
4 changes: 2 additions & 2 deletions .github/workflows/tidelift-alignment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
if: github.repository == 'Automattic/mongoose'
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 16
- name: Alignment
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/tsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
runs-on: ubuntu-latest
name: Lint TS-Files
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 14
node-version: 18

- run: npm install

Expand All @@ -40,10 +40,10 @@ jobs:
runs-on: ubuntu-latest
name: Test Typescript Types
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 14

Expand Down
64 changes: 64 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
7.5.1 / 2023-09-11
==================
* 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)
* fix: avoid unexpected error when accessing null array element on discriminator array when populating #13716 [ZSabakh](https://github.com/ZSabakh)
* types(schematypes): use DocType for instance method this #13822 #13800 [pshaddel](https://github.com/pshaddel)
* types: remove duplicated 'exists' method in Model interface in models.d.ts #13818 [ohzeno](https://github.com/ohzeno)
* docs(model): replace outdated docs on deprecated findOneAndUpdate() overwrite option #13821 #13715
* docs: add example of using `virtuals.pathsToSkip` option for `toObject()` and `toJSON()` #13798 [RobertHunter-Pluto](https://github.com/RobertHunter-Pluto)

7.5.0 / 2023-08-29
==================
* feat: use mongodb driver v5.18.1
* feat: allow top level dollar keys with findOneAndUpdate(), update() for MongoDB 5 #13786
* fix(document): make array getters avoid unintentionally modifying array, defer getters until index access instead #13774
* feat: deprecate `overwrite` option for findOneAndUpdate() #13578
* feat: add pathsToSkip option for Model.validate #13663 #10353
* feat: support alias when declaring index #13659 #13276
* fix(query): remove unnecessary check for atomic operators in findOneAndReplace() #13678
* types: add SearchMeta Interface for Atlas Search #13792 [mreouven](https://github.com/mreouven)
* types(schematypes): add missing BigInt SchemaType #13787

7.4.5 / 2023-08-25
==================
* fix(debug): avoid putting virtuals and getters in debug output #13778
* fix(model): make Model.bulkWrite() with empty array and ordered false not throw an error #13664
* fix(document): correctly handle inclusive/exclusive projections when applying subdocument defaults #13763 #13720

6.12.0 / 2023-08-24
===================
* feat: use mongodb driver v4.17.1
* fix(model): make Model.bulkWrite() with empty array and ordered false not throw an error #13664
* fix(document): correctly handle inclusive/exclusive projections when applying subdocument defaults #13763 #13720

7.4.4 / 2023-08-22
==================
* fix(connection): reset document state in between transaction retries #13726 #13698
* fix(cursor): bubble up resumeTokenChanged event from change streams #13736 #13607
* fix(query+populate): add refPath to projection by default, unless explicitly excluded #13758
* fix(schema): support 'ascending', 'asc', 'descending', 'desc' for index direction #13761 #13725
* fix(ChangeStream): add _bindEvents to addListener function for observable support #13759 [yury-ivaniutsenka](https://github.com/yury-ivaniutsenka)
* types: infer return type when using `get()`, `markModified()`, etc. with known property name literal #13739 [maybesmurf](https://github.com/maybesmurf)
* types: add missing typings for option includeResultMetadata #13747 #13746 [Idnan](https://github.com/Idnan)
* types: export InferSchemaType #13737
* docs(middleware): clarify that query middleware applies to document by default #13734 #13713
* docs: add brief note on TypeScript generic usage for embedded discriminator path() calls #13728 #10435
* docs: link v7 migration guide #13742 [Cooldogyum](https://github.com/Cooldogyum)
* docs(migrating_to_6): add note about incompatible packages #13733

6.11.6 / 2023-08-21
===================
* fix(model): avoid hanging on empty bulkWrite() with ordered: false #13701 #13684 [JavaScriptBach](https://github.com/JavaScriptBach)
* types: augment bson.ObjectId instead of adding on own type #13515 #12537 [hasezoey](https://github.com/hasezoey)

7.4.3 / 2023-08-11
==================
* fix: avoid applying map property getters when saving #13704 #13657
* fix(query): allow deselecting discriminator key #13722 #13679
* types(models+query): return lean type when passing QueryOptions with lean: true to relevant model functions like find() and findOne() #13721 #13705
* types(schema): correct return type for Schema.prototype.indexes() #13718 #13702
* types: allow accessing options from pre middleware #13708 #13633
* types: add UpdateQueryKnownOnly type for stricter UpdateQuery type checking #13699 #13630
* types(schema): support required: { isRequired: true } syntax in schema definition #13680
* docs(middleware): clarify that doc.deleteOne() doesn't run query middleware currently #13707 #13669

7.4.2 / 2023-08-03
==================
* fix(model): avoid hanging on empty bulkWrite() with ordered: false #13684 #13664
Expand Down
24 changes: 24 additions & 0 deletions docs/discriminators.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,27 @@ To update a document's discriminator key, use `findOneAndUpdate()` or `updateOne
```acquit
[require:use overwriteDiscriminatorKey to change discriminator key]
```

## Embedded discriminators in arrays

You can also define discriminators on embedded document arrays.
Embedded discriminators are different because the different discriminator types are stored in the same document array (within a document) rather than the same collection.
In other words, embedded discriminators let you store subdocuments matching different schemas in the same array.

As a general best practice, make sure you declare any hooks on your schemas **before** you use them.
You should **not** call `pre()` or `post()` after calling `discriminator()`.

```acquit
[require:Embedded discriminators in arrays]
```

## Single nested discriminators

You can also define discriminators on single nested subdocuments, similar to how you can define discriminators on arrays of subdocuments.

As a general best practice, make sure you declare any hooks on your schemas **before** you use them.
You should **not** call `pre()` or `post()` after calling `discriminator()`.

```acquit
[require:Single nested discriminators]
```
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ compiled" when I use nodemon / a testing framework?
**A**. `mongoose.model('ModelName', schema)` requires 'ModelName' to be
unique, so you can access the model by using `mongoose.model('ModelName')`.
If you put `mongoose.model('ModelName', schema);` in a
[mocha `beforeEach()` hook](https://mochajs.org/#hooks), this code will
[mocha `beforeEach()` hook](https://masteringjs.io/tutorials/mocha/beforeeach), this code will
attempt to create a new model named 'ModelName' before **every** test,
and so you will get an error. Make sure you only create a new model with
a given name **once**. If you need to create multiple models with the
Expand Down
Loading

0 comments on commit 8c3168f

Please sign in to comment.