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.
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+.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With