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