What are the Update Methods Available in MongoDB?
Dec 2, 2023
The following techniques are available in MongoDB for editing documents within a collection:
db.collection.updateOne() —
updates a maximum of one document that meets a given filter, even though the filter may be met by several documents.
db.collection.updateMany() —
Update every document that fits the given filter.
db.collection.replaceOne()-
replaces, out of the possibility of several documents matching the supplied filter, at most one document that matches the filter.
Additional Methods
Documents from a collection can also be updated using the following techniques:
db.collection.findOneAndReplace()
db.collection.findAndModify()
db.collection.findOneAndUpdate()
db.collection.bulkWrite()
For further details and examples, look to the methods’ respective reference pages.