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