Skip to content

Commit

Permalink
Merge branch '6.8' into vkarpov15/gh-12069
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 27, 2022
2 parents 68c0329 + 6f4fbee commit aa09aa1
Show file tree
Hide file tree
Showing 92 changed files with 1,376 additions and 596 deletions.
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@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b # v3.5.0
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.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@v3
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 2 additions & 2 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-20.04
name: Test Generating Docs
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup node
uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b # v3.5.0
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
with:
node-version: 16

Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
runs-on: ubuntu-latest
name: Lint JS-Files
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup node
uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b # v3.5.0
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
with:
node-version: 14

Expand Down Expand Up @@ -59,10 +59,10 @@ jobs:
MONGOMS_VERSION: ${{ matrix.mongodb }}
MONGOMS_PREFER_GLOBAL_PATH: 1
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup node
uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b # v3.5.0
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
with:
node-version: ${{ matrix.node }}

Expand Down Expand Up @@ -93,9 +93,9 @@ jobs:
runs-on: ubuntu-latest
name: Replica Set tests
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
- name: Setup node
uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b # v3.5.0
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
with:
node-version: 16
- run: npm install
Expand All @@ -110,6 +110,6 @@ jobs:
contents: read
steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
- name: Dependency review
uses: actions/dependency-review-action@v2
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@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
- name: Setup node
uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b # v3.5.0
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.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,10 +22,10 @@ jobs:
runs-on: ubuntu-latest
name: Lint TS-Files
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup node
uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b # v3.5.0
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
with:
node-version: 14

Expand All @@ -40,14 +40,14 @@ jobs:
runs-on: ubuntu-latest
name: Test Typescript Types
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup node
uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b # v3.5.0
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
with:
node-version: 12

- run: npm install

- name: Typings
run: npm run test-tsd
run: npm run test-tsd
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
6.7.3 / 2022-11-22
==================
* fix(document): handle setting array to itself after saving and pushing a new value #12672 #12656
* fix(types): update replaceWith pipeline stage #12715 [coyotte508](https://github.com/coyotte508)
* fix(types): remove incorrect modelName type definition #12682 #12669 [lpizzinidev](https://github.com/lpizzinidev)
* fix(schema): fix setupTimestamps for browser.umd #12683 [raphael-papazikas](https://github.com/raphael-papazikas)
* docs: correct justOne description #12686 #12599 [tianguangcn](https://github.com/tianguangcn)
* docs: make links more consistent #12690 #12645 [hasezoey](https://github.com/hasezoey)
* docs(document): explain that $isNew is false in post('save') hooks #12685 #11990
* docs: fixed line causing a "used before defined" linting error #12707 [sgpinkus](https://github.com/sgpinkus)

6.7.2 / 2022-11-07
==================
* fix(discriminator): skip copying base schema plugins if `applyPlugins == false` #12613 #12604 [lpizzinidev](https://github.com/lpizzinidev)
* fix(types): add UUID to types #12650 #12593
* fix(types): allow setting SchemaTypeOptions' index property to IndexOptions #12562
* fix(types): set this to doc type in SchemaType.prototype.validate() #12663 #12590
* fix(types): correct handling for model<any> #12659 #12573
* fix(types): pre hook with deleteOne should resolve this as Query #12642 #12622 [lpizzinidev](https://github.com/lpizzinidev)

6.7.1 / 2022-11-02
==================
* fix(query): select Map field with select: false when explicitly requested #12616 #12603 [lpizzinidev](https://github.com/lpizzinidev)
* fix: correctly find paths underneath single nested document with an array of mixed #12605 #12530
* fix(populate): better support for populating maps of arrays of refs #12601 #12494
* fix(types): add missing create constructor signature override type #12585 [naorpeled](https://github.com/naorpeled)
* fix(types): make array paths optional in inferred type of array default returns undefined #12649 #12420
* fix(types): improve ValidateOpts type #12606 [Freezystem](https://github.com/Freezystem)
* docs: add Lodash guide highlighting issues with cloneDeep() #12609
* docs: removed v5 link from v6 docs #12641 #12624 [lpizzinidev](https://github.com/lpizzinidev)
* docs: removed outdated connection example #12618 [lpizzinidev](https://github.com/lpizzinidev)

6.7.0 / 2022-10-24
==================
* feat: upgrade to mongodb driver 4.11.0 #12446
Expand Down
14 changes: 8 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ If you have a question about Mongoose (not a bug report) please post it to eithe
- Write typings-tests if you modify the typescript-typings. (tests are in the [test/types](https://github.com/Automattic/mongoose/tree/master/test/types) directory).

### Running the tests

- Open a terminal and navigate to the root of the project
- execute `npm install` to install the necessary dependencies
- execute `npm run mongo` to start a MongoDB instance on port 27017. This step is optional, if you have already a database running on port 27017. To spin up a specific mongo version, you can do it by executing `npm run mongo -- {version}`. E.g. you want to spin up a mongo 4.2.2 server, you execute `npm run mongo -- 4.2.2`
Expand All @@ -50,7 +51,7 @@ If you have a question about Mongoose (not a bug report) please post it to eithe

To contribute to the [API documentation](http://mongoosejs.com/docs/api.html) just make your changes to the inline documentation of the appropriate [source code](https://github.com/Automattic/mongoose/tree/master/lib) in the master branch and submit a [pull request](https://help.github.com/articles/using-pull-requests/). You might also use the github [Edit](https://github.com/blog/844-forking-with-the-edit-button) button.

To contribute to the [guide](http://mongoosejs.com/docs/guide.html) or [quick start](http://mongoosejs.com/docs/index.html) docs, make your changes to the appropriate `.pug` files in the [docs](https://github.com/Automattic/mongoose/tree/master/docs) directory of the master branch and submit a pull request. Again, the [Edit](https://github.com/blog/844-forking-with-the-edit-button) button might work for you here.
To contribute to the [guide](http://mongoosejs.com/docs/guide.html) or [quick start](http://mongoosejs.com/docs/index.html) docs, make your changes to the appropriate `.pug` / `.md` files in the [docs](https://github.com/Automattic/mongoose/tree/master/docs) directory of the master branch and submit a pull request. Again, the [Edit](https://github.com/blog/844-forking-with-the-edit-button) button might work for you here.

If you'd like to preview your documentation changes, first commit your changes to your local master branch, then execute:

Expand All @@ -59,29 +60,30 @@ If you'd like to preview your documentation changes, first commit your changes t

Visit `http://localhost:8089` and you should see the docs with your local changes. Make sure you `npm run docs:clean` before committing, because automated generated files to `docs/*` should **not** be in PRs.

#### Documentation Style Guidelines

There are some guidelines to keep the style for the documentation consistent:

- All links that refer to some other file in the mongoose documentation needs to be relative without a prefix unless required (use `guide.html` over `./guide.html` or `/docs/guide.html`)

### Plugins website

The [plugins](http://plugins.mongoosejs.io/) site is also an [open source project](https://github.com/vkarpov15/mongooseplugins) that you can get involved with. Feel free to fork and improve it as well!


## Financial contributions

We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/mongoose).
Anyone can file an expense. If the expense makes sense for the development of the community, it will be "merged" in the ledger of our open collective by the core contributors and the person who filed the expense will be reimbursed.


## Credits


### Contributors

Thank you to all the people who have already contributed to mongoose!
<a href="https://github.com/Automattic/mongoose/graphs/contributors"><img src="https://opencollective.com/mongoose/contributors.svg?width=890" /></a>


### Backers

Thank you to all our backers! [[Become a backer](https://opencollective.com/mongoose#backer)]

<a href="https://opencollective.com/mongoose#backers" target="_blank"><img src="https://opencollective.com/mongoose/backers.svg?width=890"></a>

6 changes: 3 additions & 3 deletions docs/async-await.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function awaitUpdate() {
}
```

Note that the specific fulfillment values of different Mongoose methods vary, and may be affected by configuration. Please refer to the [API documentation](./api.html) for information about specific methods.
Note that the specific fulfillment values of different Mongoose methods vary, and may be affected by configuration. Please refer to the [API documentation](api.html) for information about specific methods.

### Async Functions

Expand Down Expand Up @@ -108,7 +108,7 @@ Under the hood, [async/await is syntactic sugar](https://developer.mozilla.org/e
Due to the surprisingly simple way promises are implemented in JavaScript, the keyword `await` will try to unwrap any object with a property whose key is the string ‘then’ and whose value is a function.
Such objects belong to a broader class of objects called [thenables](https://masteringjs.io/tutorials/fundamentals/thenable).
If the thenable being unwrapped is a genuine promise, e.g. an instance of the [Promise constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), we enjoy several guarantees about how the object’s ‘then’ function will behave.
However, Mongoose provides several static helper methods that return a different class of thenable object called a [Query](./queries.html)--and [Queries are not promises](./queries.html#queries-are-not-promises).
However, Mongoose provides several static helper methods that return a different class of thenable object called a [Query](queries.html)--and [Queries are not promises](queries.html#queries-are-not-promises).
Because Queries are also *thenables*, we can interact with a Query using async/await just as we would interact with a genuine promise, with one key difference: observing the fulfillment value of a genuine promise cannot under any circumstances change that value, but trying to re-observe the value of a Query may cause the Query to be re-executed.

```javascript
Expand Down Expand Up @@ -148,4 +148,4 @@ async function observeQuery() {

You are most likely to accidentally re-execute queries in this way when mixing callbacks with async/await.
This is never necessary and should be avoided.
If you need a Query to return a fully-fledged promise instead of a thenable, you can use [Query#exec()](./api/query.html#query_Query-exec).
If you need a Query to return a fully-fledged promise instead of a thenable, you can use [Query#exec()](api/query.html#query_Query-exec).
4 changes: 2 additions & 2 deletions docs/change-streams.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Change Streams

[Change streams](https://www.mongodb.com/developer/quickstart/nodejs-change-streams-triggers/) let you listen for updates to documents in a given model's collection, or even documents in an entire database.
Unlike [middleware](/docs/middleware.html), change streams are a MongoDB server construct, which means they pick up changes from anywhere.
Unlike [middleware](middleware.html), change streams are a MongoDB server construct, which means they pick up changes from anywhere.
Even if you update a document from a MongoDB GUI, your Mongoose change stream will be notified.

The `watch()` function creates a change stream.
Expand Down Expand Up @@ -50,7 +50,7 @@ For local development, we recommend [mongodb-memory-server](https://www.npmjs.co

### Iterating using `next()`

If you want to iterate through a change stream in a [AWS Lambda function](/docs/lambda.html), do **not** use event emitters to listen to the change stream.
If you want to iterate through a change stream in a [AWS Lambda function](lambda.html), do **not** use event emitters to listen to the change stream.
You need to make sure you close your change stream when your Lambda function is done executing, because your change stream may end up in an inconsistent state if Lambda stops your container while the change stream is pulling data from MongoDB.

Change streams also have a `next()` function that lets you explicitly wait for the next change to come in.
Expand Down
21 changes: 10 additions & 11 deletions docs/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ See the [mongodb connection string spec](http://docs.mongodb.org/manual/referenc
<li><a href="#mongos_connections">Multi-mongos support</a></li>
<li><a href="#multiple_connections">Multiple connections</a></li>
<li><a href="#connection_pools">Connection Pools</a></li>
<li><a href="#v5-changes">Option Changes in v5.x</a></li>
</ul>

<h3 id="buffering"><a href="#buffering">Operation Buffering</a></h3>
Expand Down Expand Up @@ -61,7 +60,7 @@ setTimeout(function() {
}, 60000);
```

To disable buffering, turn off the [`bufferCommands` option on your schema](./guide.html#bufferCommands).
To disable buffering, turn off the [`bufferCommands` option on your schema](guide.html#bufferCommands).
If you have `bufferCommands` on and your connection is hanging, try turning
`bufferCommands` off to see if you haven't opened a connection properly.
You can also disable `bufferCommands` globally:
Expand All @@ -71,11 +70,11 @@ mongoose.set('bufferCommands', false);
```

Note that buffering is also responsible for waiting until Mongoose
creates collections if you use the [`autoCreate` option](/docs/guide.html#autoCreate).
creates collections if you use the [`autoCreate` option](guide.html#autoCreate).
If you disable buffering, you should also disable the `autoCreate`
option and use [`createCollection()`](/docs/api/model.html#model_Model-createCollection)
to create [capped collections](/docs/guide.html#capped) or
[collections with collations](/docs/guide.html#collation).
option and use [`createCollection()`](api/model.html#model_Model-createCollection)
to create [capped collections](guide.html#capped) or
[collections with collations](guide.html#collation).

```javascript
const schema = new Schema({
Expand Down Expand Up @@ -139,7 +138,7 @@ A full list of options can be found on the [MongoDB Node.js driver docs for `Mon
Mongoose passes options to the driver without modification, modulo a few
exceptions that are explained below.

* `bufferCommands` - This is a mongoose-specific option (not passed to the MongoDB driver) that disables [Mongoose's buffering mechanism](http://mongoosejs.com/docs/faq.html#callback_never_executes)
* `bufferCommands` - This is a mongoose-specific option (not passed to the MongoDB driver) that disables [Mongoose's buffering mechanism](faq.html#callback_never_executes)
* `user`/`pass` - The username and password for authentication. These options are Mongoose-specific, they are equivalent to the MongoDB driver's `auth.username` and `auth.password` options.
* `autoIndex` - By default, mongoose will automatically build indexes defined in your schema when it connects. This is great for development, but not ideal for large production deployments, because index builds can cause performance degradation. If you set `autoIndex` to false, mongoose will not automatically build indexes for **any** model associated with this connection.
* `dbName` - Specifies which database to connect to and overrides any database specified in the connection string. This is useful if you are unable to specify a default database in the connection string like with [some `mongodb+srv` syntax connections](https://stackoverflow.com/questions/48917591/fail-to-connect-mongoose-to-atlas/48917626#48917626).
Expand Down Expand Up @@ -179,7 +178,7 @@ See [this page](http://mongodb.github.io/node-mongodb-native/3.1/reference/faq/)
<h3 id="callback"><a href="#callback">Callback</a></h3>

The `connect()` function also accepts a callback parameter and returns a
[promise](./promises.html).
[promise](promises.html).

```javascript
mongoose.connect(uri, options, function(error) {
Expand Down Expand Up @@ -380,8 +379,8 @@ The `mongoose.createConnection()` function takes the same arguments as
const conn = mongoose.createConnection('mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]', options);
```

This [connection](./api.html#connection_Connection) object is then used to
create and retrieve [models](./api.html#model_Model). Models are
This [connection](api.html#connection_Connection) object is then used to
create and retrieve [models](api.html#model_Model). Models are
**always** scoped to a single connection.

```javascript
Expand Down Expand Up @@ -460,4 +459,4 @@ mongoose.createConnection(uri);

<h3 id="next">Next Up</h3>

Now that we've covered connections, let's take a look at [models](/docs/models.html).
Now that we've covered connections, let's take a look at [models](models.html).
Loading

0 comments on commit aa09aa1

Please sign in to comment.