← MongoDB learning pathMongoDB · Module 4 of 10
Data modelling
Choose between embedding and referencing.
📖 Key ideas
- Embed related data read together (e.g. address inside user).
- Reference with ids when data is large or shared (e.g. orders → user_id).
- Design for your queries: how will the app read data?
- Document size limit is 16 MB.
- 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