Delete Methods删除方法
MongoDB provides the following methods to delete documents of a collection:MongoDB提供了以下方法来删除集合中的文档:
db.collection.deleteOne() | |
db.collection.deleteMany() | |
db.collection.remove() |
Starting in MongoDB 6.1:从MongoDB 6.1开始:
To improve efficiency, MongoDB may batch multiple document deletions together.为了提高效率,MongoDB可以将多个文档删除一起批处理。Theexplain
command results contain a newBATCHED_DELETE
stage for batched document deletions.explain
命令结果包含一个新的BATCHED_DELETE
阶段,用于批量删除文档。
Additional Methods其他方法
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.有关方法的更多信息和示例,请参阅各个参考页。