Creating relations between documents

We now know how to create documents in the collections of a database. However, in real life, it is usually never enough to simply have standalone documents. We will also want to establish some kind of relations between the documents.

For example, in our database, we store information about customers and products, but we also want to store information about orders, which essentially are bills of sale stating that customer X has ordered product Y.

Let's say that Jane wants to order an Pear. To achieve this, we could let our orders look like this:

{
"customer" :
{
"firstName" : "Jane",
"lastName" : "Doley"
},
"product" :
{
"name" : "Pear",
"price" : 3
}
}

However, the disadvantages of this become clear immediately. ...

Get Learning Node.js for Mobile Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.