Http://www.mongodb.org/display/DOCS/Updating.
MongoDB supports atomic update operations to update and replace the old document or update a field in the document.
The update operation updates the matched old document with the new document object. If you only want to update the value of some fields in the document, you can use the "$" operator, as mentioned later.
MongoDB shell syntaxUpdate ():
DB. collection. Update (Criteria,Objnew,Upsert,
Multi)
Arguments:
- Criteria-Query which selects the record to update;
- Objnew-Updated object or $ operators (e.g., $ Inc) which manipulate the object
- Upsert-If this shoshould be an "upsert" operation; that is, if the record (s) do not exist, insert one.
Upsert only inserts a single document.
- Multi-If all documents matchingCriteriaShocould be updated
Note: Generally, only the first matching Document Object is updated. to update all matching document objects, the Multi option must be true.
UpsertIf the option is true, update the file or insert the file. If the option exists, update the file. Otherwise, insert the file directly.
The SAVE () operation is equivalent to the update () operation when the upsert option is true, as follows:
// X is some JSON style objectdb. mycollection. Save (x); // updates if exists; inserts if new
Well, today is the time to add more.