Skip to content

Commit

Permalink
docs(deprecations): add detail about findAndModify deprecation re: #6922
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Sep 3, 2018
1 parent 08b3163 commit 7119665
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions docs/deprecations.jade
Expand Up @@ -36,15 +36,15 @@ block content
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()`](https://mongoosejs.com/docs/api.html#mongoose_Mongoose-connect)
or [`mongoose.createConnection()`](https://mongoosejs.com/docs/api.html#mongoose_Mongoose-createConnection).
[`mongoose.connect()`](/docs/api.html#mongoose_Mongoose-connect)
or [`mongoose.createConnection()`](/docs/api.html#mongoose_Mongoose-createConnection).

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

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

```javascript
Expand All @@ -56,4 +56,39 @@ block content
To test your app with `{ useNewUrlParser: true }`, you only need to check
whether your app successfully connects. Once Mongoose has successfully
connected, the URL parser is no longer important. If you can't connect
with `{ useNewUrlParser: true }`, please [open an issue on GitHub](https://github.com/Automattic/mongoose/issues/new).
with `{ useNewUrlParser: true }`, please [open an issue on GitHub](https://github.com/Automattic/mongoose/issues/new).

## `findAndModify()`

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

```
DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.
```

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 using the MongoDB driver's `findOneAndUpdate()`
function using the [`useFindAndModify` global option](/docs/api.html#mongoose_Mongoose-set).

```javascript
// Make Mongoose use `findOneAndUpdate()`. Note that this option is `true`
// by default, you need to set it to false.
mongoose.set('useFindAndModify', false);
```

This option affects the following model and query functions. There are
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)

0 comments on commit 7119665

Please sign in to comment.