Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

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})

question from:https://stackoverflow.com/questions/35691647/whats-the-difference-between-deletemany-and-remove-in-mongodb

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 ....


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...