The dbref of MongoDB learning notes

Source: Internet
Author: User
Tags findone

Dbref:

There are two ways to model MongoDB, one is inline (Embed), and the other is connection (link). Inline is a good understanding, that is, the field content is a group, the array contains the document, and we are today to introduce another, called the link dbref. Since MongoDB has a 16M limit on the size of a single document, this restriction is also taken into account at design time.

Dbref receives the main 3 parameters:

    • Collection: Specifies the collection where the original data resides
    • ID: Specifies the ID of the referenced document
    • Database: Specifies the name of the referenced databases

Example:

To create a People collection:

Db.people.insert ({name: "Sky", Age: "A", "DEP": "CSL"})
Db.people.insert ({name: "Bill", Age: "$", "DEP": "CSL"})

Create Dbref:

Db.deps.insert ({name: "CSL", num:15, People: [Dbref ("People", ObjectId ("59b51b36a36f6ee8c75b0f68"), "Test"), Dbref (" People ", ObjectId (" 59b51b44a36f6ee8c75b0f69 ")," Test ")]})

So how do you reference it?

Db.deps.findOne ({"Name": "CSL"}). People[0].fetch ()

Db.deps.findOne ({"Name": "CSL"}). People[1].fetch ()

The dbref of MongoDB learning notes

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.