You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that buffering is also responsible for waiting until Mongoose
74
-
creates collections if you use the [`autoCreate` option](/docs/guide.html#autoCreate).
74
+
creates collections if you use the [`autoCreate` option](guide.html#autoCreate).
75
75
If you disable buffering, you should also disable the `autoCreate`
76
-
option and use [`createCollection()`](/docs/api/model.html#model_Model.createCollection)
77
-
to create [capped collections](/docs/guide.html#capped) or
78
-
[collections with collations](/docs/guide.html#collation).
76
+
option and use [`createCollection()`](api/model.html#model_Model.createCollection)
77
+
to create [capped collections](guide.html#capped) or
78
+
[collections with collations](guide.html#collation).
79
79
80
80
```javascript
81
81
constschema=newSchema({
@@ -149,15 +149,15 @@ Below are some of the options that are important for tuning Mongoose.
149
149
*`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`.
150
150
*`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.
151
151
*`useFindAndModify` - True by default. Set to `false` to make `findOneAndUpdate()` and `findOneAndRemove()` use native `findOneAndUpdate()` rather than `findAndModify()`.
152
-
*`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.
152
+
*`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.
153
153
*`promiseLibrary` - Sets the [underlying driver's promise library](http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html).
154
154
*`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).
155
155
*`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.
156
156
*`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 })`
157
157
*`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.
158
158
159
159
The following options are important for tuning Mongoose only if you are
*`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`.
163
163
*`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.
*`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).
167
167
168
168
The following options are important for tuning Mongoose only if you are
*`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).
172
172
*`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.
@@ -526,4 +526,4 @@ mongoose.connect(myUri, {
526
526
527
527
<h3id="next">Next Up</h3>
528
528
529
-
Now that we've covered connections, let's take a look at [models](/docs/models.html).
529
+
Now that we've covered connections, let's take a look at [models](models.html).
Copy file name to clipboardexpand all lines: docs/deprecations.md
+22-22
Original file line number
Diff line number
Diff line change
@@ -32,15 +32,15 @@ removed in a future version. To use the new parser, pass option
32
32
The MongoDB Node.js driver rewrote the tool it uses to parse [MongoDB connection strings](https://docs.mongodb.com/manual/reference/connection-string/).
33
33
Because this is such a big change, they put the new connection string parser
34
34
behind a flag. To turn on this option, pass the `useNewUrlParser` option to
If you use [`Model.findOneAndUpdate()`](/docs/api.html#model_Model.findOneAndUpdate),
59
+
If you use [`Model.findOneAndUpdate()`](api.html#model_Model.findOneAndUpdate),
60
60
by default you'll see one of the below deprecation warnings.
61
61
62
62
```
@@ -67,7 +67,7 @@ DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate
67
67
Mongoose's `findOneAndUpdate()` long pre-dates the MongoDB driver's `findOneAndUpdate()`
68
68
function, so it uses the MongoDB driver's [`findAndModify()` function](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findAndModify)
69
69
instead. You can opt in to using the MongoDB driver's `findOneAndUpdate()`
70
-
function using the [`useFindAndModify` global option](/docs/api.html#mongoose_Mongoose-set).
70
+
function using the [`useFindAndModify` global option](api.html#mongoose_Mongoose-set).
71
71
72
72
```javascript
73
73
// Make Mongoose use `findOneAndUpdate()`. Note that this option is `true`
@@ -86,15 +86,15 @@ no intentional backwards breaking changes, so you should be able to turn
86
86
this option on without any code changes. If you discover any issues,
87
87
please [open an issue on GitHub](https://github.com/Automattic/mongoose/issues/new).
You can also safely ignore this warning. Mongoose will not remove the legacy `useFindAndModify: true`
100
100
behavior until Mongoose 6.0.
@@ -111,7 +111,7 @@ instead.
111
111
112
112
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).
113
113
The MongoDB driver deprecated this function in favor of [`createIndex()`](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#createIndex).
114
-
Set the [`useCreateIndex` global option](/docs/api.html#mongoose_Mongoose-set) to opt in to making Mongoose use `createIndex()` instead.
114
+
Set the [`useCreateIndex` global option](api.html#mongoose_Mongoose-set) to opt in to making Mongoose use `createIndex()` instead.
115
115
116
116
```javascript
117
117
mongoose.set('useCreateIndex', true);
@@ -144,7 +144,7 @@ deleteMany, or bulkWrite instead.
144
144
```
145
145
146
146
To remove this deprecation warning, replace any usage of `remove()` with
147
-
`deleteMany()`, _unless_ you specify the [`single` option to `remove()`](/docs/api.html#model_Model.remove). The `single`
147
+
`deleteMany()`, _unless_ you specify the [`single` option to `remove()`](api.html#model_Model.remove). The `single`
148
148
option limited `remove()` to deleting at most one document, so you should
149
149
replace `remove(filter, { single: true })` with `deleteOne(filter)`.
Like `remove()`, the [`update()` function](/docs/api.html#model_Model.update) is deprecated in favor
202
-
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
203
-
`update()` with `updateOne()`, unless you use the [`multi` or `overwrite` options](/docs/api.html#model_Model.update).
201
+
Like `remove()`, the [`update()` function](api.html#model_Model.update) is deprecated in favor
202
+
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
203
+
`update()` with `updateOne()`, unless you use the [`multi` or `overwrite` options](api.html#model_Model.update).
204
204
205
205
```
206
206
collection.update is deprecated. Use updateOne, updateMany, or bulkWrite
0 commit comments