mongo change all documents on field 1

mongo change all documents on field

//Update all documents with "oldName" to "newName"
db.names.updateMany({ "name": "oldName" }, {  $set: { "name" : "newName" }  })

Here is what the above code is Doing:
1. We’re using the updateMany() method to update all documents that match the filter.
2. The filter is { “name”: “oldName” }.
3. The update is { $set: { “name” : “newName” } }.
4. The $set operator replaces the value of a field with the specified value.

Similar Posts