mongodb update value code example
Example 1: mongodb update a data in database
db.Employee.update(
{"Employeeid" : 1},
{$set: { "EmployeeName" : "NewMartin"}});
Example 2: mongodb update
db.collectionName.update({"aField":"vale1"},{$set:{"anotherField":"value2"}})
-search for documentations for more examples than search
-aField is used to find the documents
-anotherField is the field that will be updated
-You can also use the below:
-- updateOne
-- findOneAndUpdate
Example 3: mongodb replace document
try {
db.restaurant.replaceOne(
{ "name" : "Central Perk Cafe" },
{ "name" : "Central Pork Cafe", "Borough" : "Manhattan" }
);
} catch (e){
print(e);
}