Reputation: 279
Using mongodb-4.0.10 and mongoose-5.2.10
Added useFindAndModify: false
to the mongoose configuration to avoid warnings like:
DeprecationWarning: Mongoose:
findOneAndUpdate()
andfindOneAndDelete()
without theuseFindAndModify
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.
Upvotes: 7
Views: 22080
Reputation: 4177
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+.
Upvotes: 11
Reputation: 4352
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.
Upvotes: 1