Update Methods
MongoDB provides the following methods for updating documents in acollection:
db.collection.updateOne() | Updates at most a single document that match a specified filtereven though multiple documents may match the specified filter.New in version 3.2. |
db.collection.updateMany() | Update all documents that match a specified filter.New in version 3.2. |
db.collection.replaceOne() | Replaces at most a single document that match a specified filtereven though multiple documents may match the specified filter.New in version 3.2. |
db.collection.update() | Either updates or replaces a single document that match aspecified filter or updates all documents that match a specifiedfilter.By default, the db.collection.update() methodupdates a single document. To update multiple documents, usethe multi option. |
Additional Methods
The following methods can also update documents from a collection:
db.collection.findOneAndReplace()
.db.collection.findOneAndUpdate()
.db.collection.findAndModify()
.db.collection.save()
.db.collection.bulkWrite()
.
See the individual reference pages for the methods for more informationand examples.