MongoDB provides the following methods to delete documents of a collection:MongoDB提供了以下方法来删除集合中的文档:
db.collection.deleteOne() |
|
db.collection.deleteMany() |
|
db.collection.remove() |
The following methods can also delete documents from a collection:以下方法还可以从集合中删除文档:
db.collection.findOneAndDelete()
.
findOneAndDelete()
provides a sort option. The option allows for the deletion of the first document sorted by the specified order.提供排序选项。该选项允许删除按指定顺序排序的第一个文档。
db.collection.findAndModify()
.
db.collection.findAndModify()
provides a sort option. The option allows for the deletion of the first document sorted by the specified order.提供排序选项。该选项允许删除按指定顺序排序的第一个文档。
db.collection.bulkWrite()
.See the individual reference pages for the methods for more information and examples.有关更多信息和示例,请参阅各个参考页中的方法。