What's the difference between "deletemany" and "remove" in mongodb?
What's the difference between the two commands here?db.collection.deleteMany({condition})
db.collection.remove({condition})
Solution 1:
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:
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 ....