Mongo笔记6-删除

删除全部文档

The following example deletes all documents from the inventory collection:

详细介绍:https://docs.mongodb.com/manual/reference/method/db.collection.deleteMany/

> db.inventory.deleteMany({})

{ "acknowledged" : true, "deletedCount" : 10 }

> db.inventory.find()

删除匹配条件的文档(类似查询时传的条件)

To delete all documents that match a deletion criteria, pass a filter parameter to the deleteMany() method.

db.inventory.deleteMany({ status : "A" })

只删除匹配到的第一条

详细介绍:https://docs.mongodb.com/manual/reference/method/db.collection.deleteOne/#db.collection.deleteOne

db.inventory.deleteOne( { status: "D" } )

猜你喜欢

转载自blog.csdn.net/Linzhongyilisha/article/details/88047689