There are 2 approach to handle relationship
References (Normalization)
Embedded document (Denormalization)
Hybrid Approach
Using references :
let author = {
name : "Mosh"
}
let course = {
author : 'id';
// author with multiple entities:
authors : [ 'id1', 'id2']
...
}
Even tho we are referencing the id of author here, there is no relationship | or association between these 2 documents in database. eg: we can set an invalid id for a course.
Mongo DB does not care about this
let course = {
author : {
name: "mosh"
},
...
}
let author = {
name : 'mosh',
// other properties
}
let course = {
author: {
id : 'ref',
name: 'Mosh'
}
}
Which one we should pick depends on, query performance vs consistency.