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. It leads to massive data bloating, since the same customer or product can occur in several orders. Hence, its data will need to be repeated in each of the orders. It also makes maintenance a nightmare. If we want to update, say, the price of a product...