Preparing your workspace
MongoDB data modeling is based on application access patterns and commonly uses either embedded documents or references.
MongoDB gives developers flexibility in deciding how related information is stored. Embedding places related data directly inside a document and can be useful when the data is commonly read together and stays reasonably sized. References store IDs that point to documents in another collection and are useful when related data is large, shared, or independently updated. The best design depends on how the application reads and writes data, not on a universal rule to always normalize or always embed.
A course can embed a small list of lesson summaries, while a large user profile collection may reference an instructor document rather than duplicating all instructor data.
const course = {
_id: "c101",
title: "React Fundamentals",
lessons: [
{ id: "l1", title: "Components" },
{ id: "l2", title: "Props" }
],
instructorId: "u101"
};
console.log(course);The example embeds small lesson information and references the instructor by ID.