Skip to content

Commit

Permalink
Merge pull request #12692 from hasezoey/backportLinkUpdate
Browse files Browse the repository at this point in the history
[DOCS 5.x] Backport Documentation URL updates
  • Loading branch information
vkarpov15 committed Feb 20, 2023
2 parents 9caa847 + 0cd01da commit 896cd76
Show file tree
Hide file tree
Showing 34 changed files with 376 additions and 364 deletions.
17 changes: 15 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ benchmarks/benchmarks
benchmarks/benchmarks2
benchmarks/benchmarks3
benchmarks/v8.log
benchmarks/typescript/**/*.js
.DS_Store
docs/*.json
docs/source/_docs
Expand Down Expand Up @@ -40,11 +41,23 @@ test/files/main.js

package-lock.json

.config*
.config.js

# Compiled docs
docs/*.html
docs/tutorials/*.html
docs/typescript/*.html
docs/api/*.html
index.html
index.html

# Local Netlify folder
.netlify

# yarn package-lock
yarn.lock

# npm pack output
mongoose.tgz
mongoose-*.tgz

examples/ecommerce-netlify-functions/.netlify/state.json
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-fleged 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-fleged promise instead of a thenable, you can use [Query#exec()](api/query.html#query_Query-exec).
24 changes: 12 additions & 12 deletions docs/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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 +71,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 @@ -149,15 +149,15 @@ Below are some of the options that are important for tuning Mongoose.
* `useNewUrlParser` - The underlying MongoDB driver has deprecated their current [connection string](https://docs.mongodb.com/manual/reference/connection-string/) parser. Because this is a major change, they added the `useNewUrlParser` flag to allow users to fall back to the old parser if they find a bug in the new parser. You should set `useNewUrlParser: true` unless that prevents you from connecting. Note that if you specify `useNewUrlParser: true`, you **must** specify a port in your connection string, like `mongodb://localhost:27017/dbname`. The new url parser does _not_ support connection strings that do not have a port, like `mongodb://localhost/dbname`.
* `useCreateIndex` - False by default. Set to `true` to make Mongoose's default index build use `createIndex()` instead of `ensureIndex()` to avoid deprecation warnings from the MongoDB driver.
* `useFindAndModify` - True by default. Set to `false` to make `findOneAndUpdate()` and `findOneAndRemove()` use native `findOneAndUpdate()` rather than `findAndModify()`.
* `useUnifiedTopology`- False by default. Set to `true` to opt in to using [the MongoDB driver's new connection management engine](/docs/deprecations.html#useunifiedtopology). You should set this option to `true`, except for the unlikely case that it prevents you from maintaining a stable connection.
* `useUnifiedTopology`- False by default. Set to `true` to opt in to using [the MongoDB driver's new connection management engine](deprecations.html#useunifiedtopology). You should set this option to `true`, except for the unlikely case that it prevents you from maintaining a stable connection.
* `promiseLibrary` - Sets the [underlying driver's promise library](http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html).
* `poolSize` - The maximum number of sockets the MongoDB driver will keep open for this connection. By default, `poolSize` is 5. Keep in mind that, as of MongoDB 3.4, MongoDB only allows one operation per socket at a time, so you may want to increase this if you find you have a few slow queries that are blocking faster queries from proceeding. See [Slow Trains in MongoDB and Node.js](http://thecodebarbarian.com/slow-trains-in-mongodb-and-nodejs).
* `socketTimeoutMS` - How long the MongoDB driver will wait before killing a socket due to inactivity _after initial connection_. A socket may be inactive because of either no activity or a long-running operation. This is set to `30000` by default, you should set this to 2-3x your longest running operation if you expect some of your database operations to run longer than 20 seconds. This option is passed to [Node.js `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback) after the MongoDB driver successfully completes.
* `family` - Whether to connect using IPv4 or IPv6. This option passed to [Node.js' `dns.lookup()`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback) function. If you don't specify this option, the MongoDB driver will try IPv6 first and then IPv4 if IPv6 fails. If your `mongoose.connect(uri)` call takes a long time, try `mongoose.connect(uri, { family: 4 })`
* `authSource` - The database to use when authenticating with `user` and `pass`. In MongoDB, [users are scoped to a database](https://docs.mongodb.com/manual/tutorial/manage-users-and-roles/). If you are getting an unexpected login failure, you may need to set this option.

The following options are important for tuning Mongoose only if you are
running **without** [the `useUnifiedTopology` option](/docs/deprecations.html#useunifiedtopology):
running **without** [the `useUnifiedTopology` option](deprecations.html#useunifiedtopology):

* `autoReconnect` - The underlying MongoDB driver will automatically try to reconnect when it loses connection to MongoDB. Unless you are an extremely advanced user that wants to manage their own connection pool, do **not** set this option to `false`.
* `reconnectTries` - If you're connected to a single server or mongos proxy (as opposed to a replica set), the MongoDB driver will try to reconnect every `reconnectInterval` milliseconds for `reconnectTries` times, and give up afterward. When the driver gives up, the mongoose connection emits a `reconnectFailed` event. This option does nothing for replica set connections.
Expand All @@ -166,7 +166,7 @@ running **without** [the `useUnifiedTopology` option](/docs/deprecations.html#us
* `connectTimeoutMS` - How long the MongoDB driver will wait before killing a socket due to inactivity _during initial connection_. Defaults to 30000. This option is passed transparently to [Node.js' `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback).

The following options are important for tuning Mongoose only if you are
running **with** [the `useUnifiedTopology` option](/docs/deprecations.html#useunifiedtopology):
running **with** [the `useUnifiedTopology` option](deprecations.html#useunifiedtopology):

* `serverSelectionTimeoutMS` - With `useUnifiedTopology`, the MongoDB driver will try to find a server to send any given operation to, and keep retrying for `serverSelectionTimeoutMS` milliseconds. If not set, the MongoDB driver defaults to using `30000` (30 seconds).
* `heartbeatFrequencyMS` - With `useUnifiedTopology`, the MongoDB driver sends a heartbeat every `heartbeatFrequencyMS` to check on the status of the connection. A heartbeat is subject to `serverSelectionTimeoutMS`, so the MongoDB driver will retry failed heartbeats for up to 30 seconds by default. Mongoose only emits a `'disconnected'` event after a heartbeat has failed, so you may want to decrease this setting to reduce the time between when your server goes down and when Mongoose emits `'disconnected'`. We recommend you do **not** set this setting below 1000, too many heartbeats can lead to performance degradation.
Expand Down Expand Up @@ -199,7 +199,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 @@ -396,8 +396,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 @@ -526,4 +526,4 @@ mongoose.connect(myUri, {

<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).
48 changes: 24 additions & 24 deletions docs/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ removed in a future version. To use the new parser, pass option
The MongoDB Node.js driver rewrote the tool it uses to parse [MongoDB connection strings](https://docs.mongodb.com/manual/reference/connection-string/).
Because this is such a big change, they put the new connection string parser
behind a flag. To turn on this option, pass the `useNewUrlParser` option to
[`mongoose.connect()`](/docs/api.html#mongoose_Mongoose-connect)
or [`mongoose.createConnection()`](/docs/api.html#mongoose_Mongoose-createConnection).
[`mongoose.connect()`](api.html#mongoose_Mongoose-connect)
or [`mongoose.createConnection()`](api.html#mongoose_Mongoose-createConnection).

```javascript
mongoose.connect(uri, { useNewUrlParser: true });
mongoose.createConnection(uri, { useNewUrlParser: true });
```

You can also [set the global `useNewUrlParser` option](/docs/api.html#mongoose_Mongoose-set)
You can also [set the global `useNewUrlParser` option](api.html#mongoose_Mongoose-set)
to turn on `useNewUrlParser` for every connection by default.

```javascript
Expand All @@ -56,7 +56,7 @@ with `{ useNewUrlParser: true }`, please [open an issue on GitHub](https://githu

<h2 id="findandmodify"><a href="#findandmodify"><code>findAndModify()</code></a></h2>

If you use [`Model.findOneAndUpdate()`](/docs/api.html#model_Model.findOneAndUpdate),
If you use [`Model.findOneAndUpdate()`](api.html#model_Model.findOneAndUpdate),
by default you'll see one of the below deprecation warnings.

```
Expand All @@ -67,7 +67,7 @@ DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate
Mongoose's `findOneAndUpdate()` long pre-dates the MongoDB driver's `findOneAndUpdate()`
function, so it uses the MongoDB driver's [`findAndModify()` function](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findAndModify)
instead. You can opt in to using the MongoDB driver's `findOneAndUpdate()`
function using the [`useFindAndModify` global option](/docs/api.html#mongoose_Mongoose-set).
function using the [`useFindAndModify` global option](api.html#mongoose_Mongoose-set).

```javascript
// Make Mongoose use `findOneAndUpdate()`. Note that this option is `true`
Expand All @@ -86,22 +86,22 @@ no intentional backwards breaking changes, so you should be able to turn
this option on without any code changes. If you discover any issues,
please [open an issue on GitHub](https://github.com/Automattic/mongoose/issues/new).

* [`Model.findByIdAndDelete()`](/docs/api.html#model_Model.findByIdAndDelete)
* [`Model.findByIdAndRemove()`](/docs/api.html#model_Model.findByIdAndRemove)
* [`Model.findByIdAndUpdate()`](/docs/api.html#model_Model.findByIdAndUpdate)
* [`Model.findOneAndDelete()`](/docs/api.html#model_Model.findOneAndDelete)
* [`Model.findOneAndRemove()`](/docs/api.html#model_Model.findOneAndRemove)
* [`Model.findOneAndUpdate()`](/docs/api.html#model_Model.findOneAndUpdate)
* [`Query.findOneAndDelete()`](/docs/api.html#query_Query-findOneAndDelete)
* [`Query.findOneAndRemove()`](/docs/api.html#query_Query-findOneAndRemove)
* [`Query.findOneAndUpdate()`](/docs/api.html#query_Query-findOneAndUpdate)
* [`Model.findByIdAndDelete()`](api.html#model_Model.findByIdAndDelete)
* [`Model.findByIdAndRemove()`](api.html#model_Model.findByIdAndRemove)
* [`Model.findByIdAndUpdate()`](api.html#model_Model.findByIdAndUpdate)
* [`Model.findOneAndDelete()`](api.html#model_Model.findOneAndDelete)
* [`Model.findOneAndRemove()`](api.html#model_Model.findOneAndRemove)
* [`Model.findOneAndUpdate()`](api.html#model_Model.findOneAndUpdate)
* [`Query.findOneAndDelete()`](api.html#query_Query-findOneAndDelete)
* [`Query.findOneAndRemove()`](api.html#query_Query-findOneAndRemove)
* [`Query.findOneAndUpdate()`](api.html#query_Query-findOneAndUpdate)

You can also safely ignore this warning. Mongoose will not remove the legacy `useFindAndModify: true`
behavior until Mongoose 6.0.

<h2 id="ensureindex"><a href="#ensureindex"><code>ensureIndex()</code></a></h2>

If you define [indexes in your Mongoose schemas](https://mongoosejs.com/docs/guide.html#indexes), you'll see the below
If you define [indexes in your Mongoose schemas](guide.html#indexes), you'll see the below
deprecation warning.

```
Expand All @@ -111,7 +111,7 @@ instead.

By default, Mongoose 5.x calls the [MongoDB driver's `ensureIndex()` function](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#ensureIndex).
The MongoDB driver deprecated this function in favor of [`createIndex()`](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#createIndex).
Set the [`useCreateIndex` global option](/docs/api.html#mongoose_Mongoose-set) to opt in to making Mongoose use `createIndex()` instead.
Set the [`useCreateIndex` global option](api.html#mongoose_Mongoose-set) to opt in to making Mongoose use `createIndex()` instead.

```javascript
mongoose.set('useCreateIndex', true);
Expand Down Expand Up @@ -144,7 +144,7 @@ deleteMany, or bulkWrite instead.
```

To remove this deprecation warning, replace any usage of `remove()` with
`deleteMany()`, _unless_ you specify the [`single` option to `remove()`](/docs/api.html#model_Model.remove). The `single`
`deleteMany()`, _unless_ you specify the [`single` option to `remove()`](api.html#model_Model.remove). The `single`
option limited `remove()` to deleting at most one document, so you should
replace `remove(filter, { single: true })` with `deleteOne(filter)`.

Expand Down Expand Up @@ -183,24 +183,24 @@ mongoose.set('useUnifiedTopology', true);
```

The `useUnifiedTopology` option removes support for several
[connection options](/docs/connections.html#options) that are
[connection options](connections.html#options) that are
no longer relevant with the new topology engine:

- `autoReconnect`
- `reconnectTries`
- `reconnectInterval`

When you enable `useUnifiedTopology`, please remove those options
from your [`mongoose.connect()`](/docs/api/mongoose.html#mongoose_Mongoose-connect) or
[`createConnection()`](/docs/api/mongoose.html#mongoose_Mongoose-createConnection) calls.
from your [`mongoose.connect()`](api/mongoose.html#mongoose_Mongoose-connect) or
[`createConnection()`](api/mongoose.html#mongoose_Mongoose-createConnection) calls.

If you find any unexpected behavior, please [open up an issue on GitHub](https://github.com/Automattic/mongoose/issues/new).

<h2 id="update"><a href="#update"><code>update()</code></a></h2>

Like `remove()`, the [`update()` function](/docs/api.html#model_Model.update) is deprecated in favor
of the more explicit [`updateOne()`](/docs/api.html#model_Model.updateOne), [`updateMany()`](/docs/api.html#model_Model.updateMany), and [`replaceOne()`](/docs/api.html#model_Model.replaceOne) functions. You should replace
`update()` with `updateOne()`, unless you use the [`multi` or `overwrite` options](/docs/api.html#model_Model.update).
Like `remove()`, the [`update()` function](api.html#model_Model.update) is deprecated in favor
of the more explicit [`updateOne()`](api.html#model_Model.updateOne), [`updateMany()`](api.html#model_Model.updateMany), and [`replaceOne()`](api.html#model_Model.replaceOne) functions. You should replace
`update()` with `updateOne()`, unless you use the [`multi` or `overwrite` options](api.html#model_Model.update).

```
collection.update is deprecated. Use updateOne, updateMany, or bulkWrite
Expand Down Expand Up @@ -290,4 +290,4 @@ const writeStream = gfs.createWriteStream({ filename: 'test.dat' });
const conn = mongoose.createConnection('mongodb://localhost:27017/gfstest');
const gridFSBucket = new mongoose.mongo.GridFSBucket(conn.db);
const writeStream = gridFSBucket.openUploadStream('test.dat');
```
```

0 comments on commit 896cd76

Please sign in to comment.