Q6: When should you embed documents vs reference them in MongoDB?

  • Embed (Denormalization): Use when data has a 1-to-1 or 1-to-Few relationship, is accessed together frequently, and data doesn't grow unbounded (e.g., user address list).
  • Reference (Normalization): Use when data has a 1-to-Many (unbounded) or Many-to-Many relationship, data is updated independently, or document size approaches the 16MB limit.
Key Takeaways
  • Embed for atomic updates and high-speed read joins.
  • Reference for large, unbounded collections or shared entities.
Knowledge Check

Which pattern is recommended for storing a blog post's tags (5 to 10 tags per post)?