Database Manual / CRUD Operations / Update

Update Methods更新方法

MongoDB provides the following methods for updating documents in a collection:MongoDB提供了以下方法来更新集合中的文档:

db.collection.updateOne()Updates at most a single document that match a specified filter even though multiple documents may match the specified filter.即使多个文档可能与指定的筛选器匹配,也最多更新一个与指定筛选器匹配的文档。
db.collection.updateMany()Update all documents that match a specified filter.更新与指定筛选器匹配的所有文档。
db.collection.replaceOne()Replaces at most a single document that match a specified filter even though multiple documents may match the specified filter.即使多个文档可能与指定的筛选器匹配,也最多替换与指定筛选器匹配的单个文档。

Additional Methods附加方法

The following methods can also update documents from a collection:以下方法也可以更新集合中的文档:

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