Docs HomeMongoDB Manual

Delete Methods删除方法

MongoDB provides the following methods to delete documents of a collection:MongoDB提供了以下方法来删除集合中的文档:

db.collection.deleteOne()Delete at most a single document that match a specified filter even though multiple documents may match the specified filter.即使多个文档可能与指定的筛选器匹配,也最多删除一个与指定筛选器匹配的文档。
db.collection.deleteMany()Delete all documents that match a specified filter.删除与指定筛选器匹配的所有文档。
db.collection.remove()Delete a single document or all documents that match a specified filter.删除单个文档或与指定筛选器匹配的所有文档。

Starting in MongoDB 6.1:从MongoDB 6.1开始:

  • To improve efficiency, MongoDB may batch multiple document deletions together.为了提高效率,MongoDB可以将多个文档删除一起批处理。
  • The explain command results contain a new BATCHED_DELETE stage for batched document deletions.explain命令结果包含一个新的BATCHED_DELETE阶段,用于批量删除文档。

Additional Methods其他方法

The following methods can also delete documents from a collection:以下方法也可以从集合中删除文档:

See the individual reference pages for the methods for more information and examples.有关方法的更多信息和示例,请参阅各个参考页。