MongoDB. Update

Source: Internet
Author: User

I recently started to read some articles about MongoDB.ArticleMore and more think that it is what I need. However, I know very little about it first. I can see that it is a superficial phenomenon.

I started reading the MongoDB introduction written by Karl yesterday. There are 33 pages in total. I feel that this article is not very clear and I need to try and understand it myself.

For traditional databases, crud (= create + read + update + Delete) is the core, and U is the most noteworthy! Let's take a look at the update part and practice it.

Update has four parameters: first, selector, second, newvalue, third, upserts, fourth, and multipleupdate.

Like CRD, selector is a search selector that clarifies the query conditions;

Newvalue is the content to be updated. There are two basic conditions: $ set, $ Inc, and $ push:

Scenario 1: If there is no parameter, newvalue replaces the content of the original selector;

Scenario 2: With parameters, $ set is to update newvalue for the specified field; $ Inc requires that the specified field be a numerical value and the value of newvalue; $ push requires that the specified field be an array, add newvalue to the array. Of course, there must be a lot of parameters, so I will only learn so much!

I will not expand it. I will repeat it again.CodeYou will know what it means;

Upserts is a logical value parameter. The default value is false. That is, if the document is queried Based on selector, the update is executed. If no information is found, nothing is done. If it is set to true, the meaning is obvious. If it is not found, create a new document to store selector and newvalue.

Multipleupdate is also a logical value parameter. The default value is false. That is, the first document is updated when the parameters are found based on the selector query. If the value is set to true, update all the retrieved documents.

Two MongoDB entry notes






Fields vs. Columns
MongoDB 1st step

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.