Use the DB. Table name. Update () Updates data The specified table must be present with the following syntax: Db.collection.update (criteria, objnew, Upsert, Multi) criteria:update query criteria, Similar to the SQL update query within where the Objnew:update object and some updated operators (such as $, $inc ... ), and so on, can also be understood as Upsert after the set in SQL Update query: This parameter means that if there is no record of update, insert Objnew,true is inserted, default is False, not inserted. Multi:mongodb default is False, only update the first record found, if this parameter is true, the condition is checked out all the records are updated. For example we have a table that is nopk> Db.noPK.find () {"_id": ObjectId ("5a50642b908e6b07a84472a2"), "name": "JavaScript", "Value": " Vue.js "} {" _id ": ObjectId (" 5a50655b908e6b07a84472a3 ")," name ":" Python "," type ":" Script "} we need to name the value of Python more New for the Shell to note is that MONGO is case-sensitive when you write Python incorrectly to Python is unable to update the data > db.noPK.update ({"name": "Python"}, {$set: {"name": "Shell"}} ) Writeresult ({"nmatched": 0, "nupserted": 0, "nmodified": 0}) > The returned result shows that the update entry is 0 because it was incorrectly written to python > Db.noPK.update ( {"Name": "Python"}, {$set: {"name": "Shell"}}) Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1}) > Db.nopk.f IND () {"_id": ObjectId ("5a50642b908e6b07a84472a2"), "name": "JAvascript "," Value ":" Vue.js "} {" _id ": ObjectId (" 5a50655b908e6b07a84472a3 ")," name ":" Shell "," type ":" Script "}>& NBSP;MONGODB Update is the default only update matches to the first data if we want to update all the matches to the data, then multi to be set to true for example: Our NOPK table has 3 name is shell> Db.noPK.find () {"_id": ObjectId ("5a50642b908e6b07a84472a2"), "name": "JavaScript", "Value": "Vue.js"} {"_id": objecti D ("5a50655b908e6b07a84472a3"), "name": "Shell", "type": "Script"} {"_id": ObjectId ("5a506b40908e6b07a84472a4"), "name" ":" Shell "," type ":" Script "} {" _id ": ObjectId (" 5a506b9d908e6b07a84472a5 ")," name ":" Shell "," type ":" Script "," Scri Pt_type ":" Bash_shell "}> we want to update them all > db.noPK.update ({" Name ":" Shell "}, {$set: {" name ":" Xshell "}}, False, True) Writeresult ({"nmatched": 3, "nupserted": 0, "nmodified": 3})
MongoDB Update Data