โ† MongoDB learning path
MongoDB ยท Module 4 of 10

Data modelling

Choose between embedding and referencing.

๐Ÿ“– Key ideas

  1. Embed related data read together (e.g. address inside user).
  2. Reference with ids when data is large or shared (e.g. orders โ†’ user_id).
  3. Design for your queries: how will the app read data?
  4. Document size limit is 16 MB.
  5. Avoid unbounded arrays that grow forever.
๐Ÿ’ก Real-life example: Embedding is keeping the charger in the phone box; referencing is a note saying "charger in drawer 3".
EmbeddingStoring related data inside a document
ReferencingStoring an id pointing to another document
16 MBMax document size
Unbounded arrayArray that grows without limit