JaySparkexel
JaySparkexel

Reputation: 165

What is difference between deleteOne() and findOneAndDelete() operation in MongoDB?

This both operations delete one object. Is there any performance difference between them or both are same?

Upvotes: 2

Views: 3154

Answers (1)

Abdul Rehman Sayed
Abdul Rehman Sayed

Reputation: 6672

findOneAndDelete has the sort parameter which can be used to influence which document is updated. It also has a TimeLimit parameter which can control within which operation has to complete.

From the docs : https://docs.mongodb.com/v3.2/reference/method/db.collection.findOneAndDelete/

Deletes a single document based on the filter and sort criteria, returning the deleted document.

https://docs.mongodb.com/manual/reference/method/db.collection.deleteOne/

Removes a single document from a collection.

Upvotes: 1

Related Questions