replace the document to update mongo code example
Example 1: how to update subdocument mongodb
db.getCollection('products')
.update({"reviews.user": ObjectId("5f6e2e0b70eb0208fc8401a1")},
{$set: {"reviews.$.rating": NumberInt(3)}})
Example 2: mongodb replace document
try {
db.restaurant.replaceOne(
{ "name" : "Central Perk Cafe" },
{ "name" : "Central Pork Cafe", "Borough" : "Manhattan" }
);
} catch (e){
print(e);
}