Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Delete and remove

What is the difference between findOneAndDelete and findOneAndRemove and which method must be used to delete document.

There is no such method in MongoDB. See the list of delete methods.

To be short:

  • use .deleteOne(), if you need to delete exactly 1 document.
  • use .deleteMany(), if you need to delete more than 1 document.
  • use .findOneAndDelete(), if you need to delete exactly 1 document, but also return its copy to the application.

Like I wrote in the MongoDB University forum findOneAndRemove() is mongoose. So if you use mongoose, use findOneAndRemove() and if you use mongo use findOndAndDelete().