{"id":700,"hash":"effb70a3c94719cfd85c4aaafbbecf8e436cc6f4389ea18e36ddb9da3e69df7c","pattern":"DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead?","full_message":"I am using mongoose findOneAndUpdate but still getting the error,\n\n  DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.\n\nBut I am not even using findAndModify, why is it converting my query to findAndModify?","ecosystem":"npm","package_name":"node.js","package_version":null,"solution":"You need to set the option in the query useFindAndModify to false, as mentioned in the docs.\n\n(search keyword Currently supported options are)\n\n  'useFindAndModify': true by default. Set to false to make\n  findOneAndUpdate() and findOneAndRemove() use native\n  findOneAndUpdate() rather than findAndModify().\n\nand if you see the definition file of mongoose, where mentioned that it calls findAndModify update command.\n\n /**\n  * Issues a mongodb findAndModify update command.\n  * Finds a matching document, updates it according to the update arg, \n    passing any options,\n  * and returns the found document (if any) to the callback. The query \n    executes immediately\n  * if callback is passed else a Query object is returned.\n  */\n findOneAndUpdate(): DocumentQuery<T | null, T>;\n\nRecently updated in the mongoose docs (Click here) for these deprecation  where mentioned: \n\n  Mongoose's findOneAndUpdate() long pre-dates the MongoDB driver's\n  findOneAndUpdate() function, so it uses the MongoDB driver's\n  findAndModify() function instead.\n\nThere are three ways or more by which you can avoid the use of FindAndModify:\n\nAt Global level: Set the option to false.\n\n// Make Mongoose use `findOneAndUpdate()`. Note that this option is `true`\n// by default, you need to set it to false.\nmongoose.set('useFindAndModify', false);\n\nAt connection level: we can configure using the connection options:\n\n    mongoose.connect(uri, { useFindAndModify: false });\n\nAt Query level: \n\n   await ModelName.findOneAndUpdate({matchQuery},\n   {$set: updateData}, {useFindAndModify: false});","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/52572852/deprecationwarning-collection-findandmodify-is-deprecated-use-findoneandupdate","votes":96,"created_at":"2026-04-19T04:51:30.407621+00:00","updated_at":"2026-04-19T04:51:30.407621+00:00"}