Skip to content
Databases for Developers

Lesson 6 of 10 · 22 min

x
6/10

Lesson position in the course — not completion. Use Mark Complete to track finished lessons (saved in this browser).

NoSQL: Document Stores

Document databases store JSON-like documents instead of rows. Each document can have a different shape, making them ideal for data with evolving schemas — user profiles, content, product catalogs, and mobile app backends where the fields vary by type or version.

MongoDB and Firestore are the most widely used document stores. The key difference from relational databases: there are no JOINs. You either embed related data inside the document (fast reads, larger documents) or reference it by ID and fetch separately (normalized, slower). The right choice depends on how you access the data — embed things you always read together.

Before
Relational (two queries to build a profile)
1const user = await db.users.findOne({ id });2const posts = await db.posts.find({ userId: id });
After
Document (one read, everything embedded)
1// User document with embedded recent posts2{3  "_id": "user_123",4  "name": "Alice",5  "email": "alice@example.com",6  "recentPosts": [7    { "title": "My First Post", "publishedAt": "2026-06-01" },8    { "title": "On Databases",  "publishedAt": "2026-06-15" }9  ]10}

Check your understanding

  • When should you embed related data in a document?Show answer

    Answer

    When you almost always read it together and the embedded set stays bounded.
  • When should you reference by ID instead?Show answer

    Answer

    When related data is large, independently updated, or read on different paths.
  • What trade-off do you lose vs relational JOINs?Show answer

    Answer

    You typically cannot JOIN across collections the same way — you embed or fetch separately.
Previous

Progress is saved in this browser.

Next Lesson