MongoDB Learning Notes ~ Self-encapsulated curd operations (prerequisites for on-demand updates)

Source: Internet
Author: User

Back to Catalog

We introduced the uncle in the package of MONGO warehousing, which introduced a few good curd operations, and for on-demand update of the internal sub-object, it is conditional, that is, your child object can not be null, that is, when we set up the main object, we should assign the initial value to the child object, That is new it, hehe.

The right MONGO collection

For sub-objects that have the initial value assigned, there are two ways to be aware of the following when updating as needed

1 The _id of the child object, if it already exists, updates its value

2 The _id of the child object, if it does not exist, or if it is not displayed as a _id assignment, adds a new record, that is, _id from the newly generated

In the case of an entity update, the value in the entity overrides the value of the original table, and the code that is updated as needed is shown below

            #regionUpdate on DemandRepository1. Update<Person> (i =NewPerson {Id="556D531E2683C818C86CADDB", Address=NewAddress {Id="556d531e2683c818c86ca123",/*no ID (or ID not present in the collection) is the addition of an element to the list, the ID exists to update the specified element*/Province="Luanxian", City="111 Hunan Occupation Master", District="Community", Seconds=1}, Addlist=NewList<address>() {                    NewAddress {/*no ID (or ID not present in the collection) is the addition of an element to the list, the ID exists to update the specified element*/Id="556d531e2683c818c86cadde", Province="Luanxian", City="Hunan occupies master ddd", District="Community", Seconds=1                      }}            }); #endregion

For the whole update, the same problem, of course, if you need to get the table records from the library

           #regionFull updatevare1 = Repository1. Find ("556D531E2683C818C86CADDB"); E1. Name="Wet"; E1. Address.city="Beijing 123"; /*iterate through the original collection, bulk assign values*/E1. Addlist.foreach (i={i.city="Big Account";            }); /*assign a value to each object individually, without specifying an ID that is automatically generated*/E1. Addlist=NewList<address> {            Newaddress{city="was accounted for 1"},            Newaddress{city="was accounted for 2"}            }; Repository1.            Update (E1); #endregion

For Monodb we still need to continue to explore, research ...

Back to Catalog

MongoDB Learning Notes ~ Self-encapsulated curd operations (prerequisites for on-demand updates)

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.