I am not getting the difference between remove[1] and deleteMany[2]
Only difference I can see is in terms of what gets returned
deleteMany returns:
deletedCount & A boolean acknowledged as true if the operation ran with write concern or false if write concern was disabled
While remove returns:
A WriteResult object that contains the status of the operation.
Semantically they look the same.
When should you use which?
Thanks.
Ref:
[1]: https://docs.mongodb.com/manual/reference/method/db.collection.remove/
[2]: https://docs.mongodb.com/manual/reference/method/db.collection.deleteMany/
On Wednesday, 13 July 2016 21:05:18 UTC+10, Mayank Jain wrote:
I am not getting the difference between remove[1] and deleteMany[2]
…
Hi Mayank,
The deleteMany() method was added in MongoDB 3.2 to make the mongo shell CRUD API consistent with the driver API. The remove() method is the historical interface which is available for backward compatibility.
For more background, see Jesse’s blog post on The MongoDB Shell’s New CRUD API.
When should you use which?
If you are writing admin scripts and need compatibility for mongo shells older than 3.2, you should use the older API. For MongoDB 3.2+ I would recommend using the new CRUD API.
Regards,
Stephen