Skip to content

Embedded vs Referenced

Unlike SQL’s strict relational tables, MongoDB gives us the flexibility to format data around how our application will actually read it. MongoDB lets us model relationships in two main ways: Embedded and Referenced.

Embedded vs Referenced Architecture

Fig 1: Embedded vs. Referenced Architecture

Embedded data means storing the related data inside the parent document.

  • The Pros: Reads are blazing fast because it only takes one query to get the parent and all related child details.
  • The Cons: Updates can be difficult (modifying nested arrays) and data replication (if sub-data is reused) can cause inconsistency.

Referenced data means storing the related data in its own separate collection, while the parent document simply stores an ObjectId (a reference) to it.

  • The Philosophy: “The related thing has its own life outside of the parent.”
  • The Pros: Highly reusable. You can update the referenced document once and every parent that references it gets the updated context automatically.
  • The Cons: Requires multiple queries to retrieve the parent and the details of the referenced child.
Professor Solo

For our portfolio project, we will combine both strategies: * Categories will be Referenced (reusable, cleanly populated). * Tags and Screenshots will be Embedded (simplifies data models, fast reads).

FactorEmbeddedReferenced
LocationInside Parent Doc (Subdocuments/Arrays)Independent Collection (Mapped via ObjectId)
Best ForMetadata that only matters inside its parent. E-commerce order receipts, blog post tags.Generalized concepts used widely across the app. Categories, Authors, Users.
Speed⚡ Extremely Fast execution. Returns instantly with parent search.⏳ Moderate. Requires .populate() queries to append data.
ModificationsDifficult to normalize. Needs complex array modifications if changing data identically across all docs.Easy to normalize. Updates one item independently and it updates everywhere simultaneously.

MongoDB Schema Design: Relationships

📘 Embedded vs Referenced Data Infographic (PNG)

Let’s look at a simpler, more performant approach for lightweight metadata: “Tags”.