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.即使多个文档可能与指定的筛选器匹配,也最多删除与指定筛选器匹配的单个文档。

New in version 3.2.版本3.2中的新功能。

db.collection.deleteMany()

Delete all documents that match a specified filter.删除与指定筛选器匹配的所有文档。

New in version 3.2.版本3.2中的新功能。

db.collection.remove() Delete a single document or all documents that match a specified filter.删除单个文档或与指定筛选器匹配的所有文档。

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.有关更多信息和示例,请参阅各个参考页中的方法。