MongoDB Descriptor Table Relationships

Source: Internet
Author: User

Mode one: Embedded

> Db.person.find ({name: ' ZJF '}). Pretty ()

{

"_id": ObjectId ("592ffd872108e8e79ea902b0"),

"Name": "ZJF",

"Age": 30,

"Address": {

"Province": "Henan Province",

"City": "Nanyang",

"Building": "Tongbai County"

}

}

the Address embed as an object into the person , it can also be an array here.

There is data redundancy in this way. And the address is written dead in person, for all person, their address is a separate, not can be shared as a class.

Mode two: quoted type

> Db.person.find ({name: ' Xhj '}). Pretty ()

{

"_id": ObjectId ("593011C8A92497992CDFAC10"),

"Name": "Xhj",

"Age": 30,

"Address": ObjectId ("59314b07e693aae7a5eb72ab")

}

> Db.address.find (). Pretty ()

{

"_id": ObjectId ("59314b07e693aae7a5eb72ab"),

"Province": "Henan Province",

"City": "Nanyang",

"Building": "Tongbai County"

}

Person is stored in the address point the reference. The disadvantage of this approach is that it takes a join to get all the data, but MongoDB does not support direct join syntax.

MongoDB Descriptor Table Relationships

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.