The difference among db.collection.update({…data}), db.collection.updateOne({…data}) and db.collection.updateMany({…data})?
Updating objects in mongoDB happens with update, updateOne, updateMany.
Before MongoDB 3.2, update method can be used to update either one or multiple documents.
After version 3.2 two update methods were introduced, updateOne and updateMany.
update: now deprecated, modifies an existing document or documents.
By default, update method updates a single document.
If we want to modify multiple documents, we pass an option multi: true to update all
documents that match query criteria. To update multiple documents,
db.customers.update({firstName: 'Tomas'}, {$set: {phone: 091xxxx}}, {multi: true})
To update single document,
db.customers.update({firstName: 'Tomas'}, {$set: {phone: 091xxxx}})
Now on the newer versions of mongoDB,
It has been introduced two new methods which replaces the old update method.
updateOne: updates only first matching document with firstName ‘Tomas’
db.customers.updateOne({firstName: 'Tomas'}, {$set: {phone: 091xxxx}})
updateMany: will update all matching documents with firstName ‘Tomas’
db.customers.updateMany({firstName: 'Tomas'}, {$set: {phone: 091xxxx}})