Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The options [useFindAndModify] is not supported

Using mongodb-4.0.10 and mongoose-5.2.10

Added useFindAndModify: false to the mongoose configuration to avoid warnings like:

DeprecationWarning: Mongoose: findOneAndUpdate() and findOneAndDelete() without the useFindAndModify option set to false are deprecated.

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

But now 'the options [useFindAndModify] is not supported' is coming on running the app.

like image 305
Bilal Khan Avatar asked Jan 02 '20 08:01

Bilal Khan


2 Answers

For others who are facing this issue, useFindAnyModify is not supported if you are using mongoose version 6+.

To solve this either we can remove useFindAnyModify or downgrade mongoose version to use v5+.

like image 133
Kunal Tyagi Avatar answered Oct 12 '22 17:10

Kunal Tyagi


First, update mongoose to ^latest (5.8.X) version.

Then rewrite you code and try to use it like this

mongoose.connect(`mongodb+srv://${login}:${password}@${hostname}/${auth_db}`, {
    useNewUrlParser: true,
    useFindAndModify: false,
    retryWrites: true,
    w: "majority",
});

mongoose.Promise = global.Promise;

Also, according to mongoose docs on findOneAndUpdate you could use findOne and update docs via triggering .save on result.

like image 44
AlexZeDim Avatar answered Oct 12 '22 17:10

AlexZeDim