Databases for Developers

Lesson 6 of 10 · 22 min

x
60%

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)
const user = await db.users.findOne({ id });
const posts = await db.posts.find({ userId: id });
After
Document (one read, everything embedded)
// User document with embedded recent posts
{
  "_id": "user_123",
  "name": "Alice",
  "email": "alice@example.com",
  "recentPosts": [
    { "title": "My First Post", "publishedAt": "2026-06-01" },
    { "title": "On Databases",  "publishedAt": "2026-06-15" }
  ]
}

Key Takeaway

Embed data you always read together; reference data you read independently — this single rule drives document schema design.

PreviousNext Lesson