npmnode.js95% confidence\u2191 96

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

Full error message
I am using mongoose findOneAndUpdate but still getting the error,

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

But I am not even using findAndModify, why is it converting my query to findAndModify?

You need to set the option in the query useFindAndModify to false, as mentioned in the docs. (search keyword Currently supported options are) 'useFindAndModify': true by default. Set to false to make findOneAndUpdate() and findOneAndRemove() use native findOneAndUpdate() rather than findAndModify(). and if you see the definition file of mongoose, where mentioned that it calls findAndModify update command. /** * Issues a mongodb findAndModify update command. * Finds a matching document, updates it according to the update arg, passing any options, * and returns the found document (if any) to the callback. The query executes immediately * if callback is passed else a Query object is returned. */ findOneAndUpdate(): DocumentQuery<T | null, T>; Recently updated in the mongoose docs (Click here) for these deprecation where mentioned: Mongoose's findOneAndUpdate() long pre-dates the MongoDB driver's findOneAndUpdate() function, so it uses the MongoDB driver's findAndModify() function instead. There are three ways or more by which you can avoid the use of FindAndModify: At Global level: Set the option to false. // Make Mongoose use `findOneAndUpdate()`. Note that this option is `true` // by default, you need to set it to false. mongoose.set('useFindAndModify', false); At connection level: we can configure using the connection options: mongoose.connect(uri, { useFindAndModify: false }); At Query level: await ModelName.findOneAndUpdate({matchQuery}, {$set: updateData}, {useFindAndModify: false});

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/effb70a3c94719cfd85c4aaafbbecf8e436cc6f4389ea18e36ddb9da3e69df7c
hash \u00b7 effb70a3c94719cfd85c4aaafbbecf8e436cc6f4389ea18e36ddb9da3e69df7c
DeprecationWarning: collection.findAndModify is deprecated.… — DepScope fix | DepScope