mongodb shell replace document field code example
Example 1: mongo change all documents on field
//Update all documents with "oldName" to "newName"
db.names.updateMany({ "name": "oldName" }, { $set: { "name" : "newName" } })
Example 2: mongodb replace document
try {
db.restaurant.replaceOne(
{ "name" : "Central Perk Cafe" },
{ "name" : "Central Pork Cafe", "Borough" : "Manhattan" }
);
} catch (e){
print(e);
}