We already discussed one to one relations in MongoDB, and the main conclusion was that you should design your collections according to the most frequent access pattern. With one to many relations, this is still valid, but other factors may come into play.
Let’s look at a simple problem: we are a shop and we want to store customers’ information as well as their orders. Each customer can make several orders, this is a one to many relation. With MySQL or any relational database system, we would create 2 tables:
CREATE TABLE customer ( customer_id int(11) NOT NULL AUTO_INCREMENT, name varchar(50) NOT NULL DEFAULT '', zipcode varchar(10) DEFAULT NULL, PRIMARY KEY (customer_id) ) ENGINE=InnoDB; CREATE TABLE orders ( order_id int(11) NOT NULL AUTO_INCREMENT, customer_id int(11) NOT NULL DEFAULT '0', …[Read more]