MongoDB – Update Document:
In MongoDB, updating a document can be done through below provided methods.
Syntax:
db.collection.updateOne() ---> New command in version 3.2.
This command will update a single document even though the filter or condition have multiple document that may match to update.
db.collection.updateMany() ---> New command in version 3.2.
This command will update all documents that match the condition.
db.collection.replaceOne() ---> New command in version 3.2.
This command will replace a single document that match the condition.
db.collection.update()
This command can update either a single document or multiple documents that match the condition.
Example:
db.students.update( { "firstname": "Manju" }, { $set: { "city": "delhi"}, $currentDate: { lastModified: true } } )