What's the difference between "deletemany" and "remove" in mongodb?

Mongodb

Mongodb Problem Overview


What's the difference between the two commands here?
db.collection.deleteMany({condition})
db.collection.remove({condition})

Mongodb Solutions


Solution 1 - Mongodb

They do the same. The difference is the values that return.

With remove():

> db.ticker.remove({"name": "Bitcoin"})
WriteResult({ "nRemoved" : 2 })

With deleteMany():

> db.ticker.deleteMany({"name": "Bitcoin"})
{ "acknowledged" : true, "deletedCount" : 2 }

Solution 2 - Mongodb

As far as I can say,

> db.collection.deleteMany

Returns:	
   A document containing:
       > A boolean acknowledged as true if the operation ran with write concern or false if write concern was disabled
       > deletedCount containing the number of deleted documents

REF: db.collection.deleteMany

Where as

> db.collection.remove

return WriteResult

And to remove a single document, there a similar command, db.collection.removeOne where as with db.collection.remove you need to set and option called justOne option to limit delete to 1 document.

Otherwise I guess they are similar.

> node.js drivers

When talking about node.js drivers, remove has been deprecated (and may be removed in future releases) and deleteOne or deleteMany.

Hope this makes sense ....

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlookView Question on Stackoverflow
Solution 1 - MongodbRevol89View Answer on Stackoverflow
Solution 2 - MongodbDave AmitView Answer on Stackoverflow