MongoDB's Upsert

Source: Internet
Author: User
Tags mongodb update

The three parameters of the MongoDB Update method are Upsert, which is a Boolean type and the default is False. When it is true, the Update method first finds the record that matches the first parameter, and when it is updated with the second parameter, inserts one if no record matching the first argument is found (Upsert's name is also interesting as a hybrid: Update+insert)

Look at the following example:

Db.post.update ({count:100},{"$inc": {count:10}},true);

When the count=100 record is not found, automatically inserts a count=100, then adds 10, and finally gets a count=110 record.

MongoDB's Upsert

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.