MongoDB Relationships

Relationships in MongoDB are something that creates a linkage between two or more documents that we create. In other words, Relationships in MongoDB can be defined as different documents that are linked logically.

MongoDB Relationships Types

Different types of relationships that we have in MongoDB are:

  1. One to One
  2. One to Many
  3. Many to One
  4. Many to Many

Approaches for Data Modeling

mongodb Approaches for Data Modeling

1) Embedded Approach (Denormalization Approach)

This approach follows maintaining all the related data stored inside a single document in the form of embedded documents. This approach is followed if we have to deal with the following relationships in MongoDB:

  1. One to OneĀ 
  2. One to Many

However, we are going to discuss all the types of these relationships in the latter part of this course, individually.

2) Referenced Approach (Normalized Approach)

This approach follows maintaining all the related data in other separate documents. Also, the related documents are connected to each other by passing a common '_id' key of the child document in the parent document. This approach is followed if we have to deal with the following relationships in MongoDB:

  1. Many to One
  2. Many to Many