Database Reference
In-Depth Information
Here is a collection showing the network example using parent references:
Employee :
{ _id : "Mary", employeeFirstName : "Mary"
},
{ _id : "Bob", employeeFirstName : "Bob",
managerID : [ "Mary", "Jill" ] },
{ _id : "Jill", employeeFirstName : "Jill",
managerID : [ "Mary" ] },
{ _id : "Ken", employeeFirstName : "Ken",
managerID : [ "Bob" ] },
{ _id : "Jane", employeeFirstName : "Jane",
managerID : [ "Bob", "Ken", "Sven" ] },
{ _id : "Sven", employeeFirstName : "Sven",
managerID : [ "Jill" ] }
Note that in these examples we are illustrating references, but if we would like to illustrate
embedding the manager information with each employee, these collections would look
very similar because we just have the two fields, _id and employeeFirstName . Also note
that there are other embed and reference design options available in addition to what is
shown in this example.
K EYS
There is a lot of data out there, but how do you sift through it all to find what you're looking
for? That's where keys come in. A key is one or more attributes whose purposes include en-
forcing rules, efficiently retrieving data and allowing navigation from one entity to another.
This section explains candidate (primary and alternate), surrogate, foreign, and secondary
keys.
CANDIDATE KEY (PRIMARY AND ALTERNATE KEYS)
A candidate key is one or more data elements that uniquely identify an entity instance. The
Library of Congress assigns an ISBN (International Standard Book Number) to every title.
The ISBN uniquely identifies each title and is, therefore, the title's candidate key. When
the ISBN for this title, 9781935504702 , is entered into many search engines and database
systems, the topic entity instance Data Modeling for MongoDB will be returned (try it!).
Search WWH ::




Custom Search