MongoDB study Note 6 updating

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.