What is the difference between remove vs deleteMany?

3,075 views
Skip to first unread message

Mayank Jain

unread,
Jul 13, 2016, 7:05:18 AM7/13/16
to mongodb-user
Hi,

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/


Stephen Steneker

unread,
Jul 13, 2016, 7:22:00 AM7/13/16
to mongodb-user

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


Mayank Jain

unread,
Jul 13, 2016, 8:20:21 AM7/13/16
to mongodb-user
Thank you :)
Reply all
Reply to author
Forward
0 new messages