MongoDB: Document Modeling and Operations

Embedding against referencing, aggregation pipelines, replica sets and sharding - and the schema design that decides everything else.

Taught by Noshad Alam 7 lessons 41 min Published 30 Nov 2026

MongoDB stores documents - BSON objects with nested structure, arrays and no required shape - and the reason it succeeded is that a document often matches what an application actually wants: one read returns the whole order, lines and all, with no joins. The reason projects fail with it is the same flexibility, used without a decision.

Overview

"MongoDB is schemaless" is the most expensive sentence in this subject. MongoDB does not *enforce* a schema unless you ask it to, which is not the same as not having one. Your application has a schema; the only question is whether it is written down in the database, in a validator, or nowhere - and "nowhere" means it lives in the heads of whoever wrote the code, drifts silently, and surfaces as a `TypeError` in a report six months later. This course treats schema design as the central discipline it is, and Module 2 is the longest module for that reason.

The other half of the course is operational. A single `mongod` is a toy; production MongoDB is a **replica set**, where a primary takes writes, secondaries replicate, and an election promotes a new primary when the old one fails. On top of that sit **read and write concerns**, which let you choose, per operation, how durable and how current you want to be - a genuinely useful control and one that is routinely left at a default nobody chose. And beyond a certain size, **sharding**, where the shard key is a decision you make once and change with great difficulty.

Seven modules, about 90 hours. The capstone is a product catalogue with faceted search, order transactions and change-stream notifications.

Introduction

This course assumes the programme's shared foundations. It does not assume SQL, though if you know SQL you will spend the first two modules unlearning the reflex to normalise everything.

For a sandbox, run MongoDB 7 or later. The quickest route to a *realistic* environment is a three-node replica set, because several features in this course - transactions, change streams, read concerns - **require** a replica set and simply do not exist on a standalone server. `mongod --replSet rs0` on three ports, or a Docker Compose file, or `mongosh` against a free Atlas M0 cluster, which is a real replica set.

Use **`mongosh`** as your shell: it is JavaScript, so you can write loops and build test data in the shell itself. **Compass** is the graphical client and its *Explain* and *Schema* tabs are genuinely useful - the Schema tab samples a collection and shows you what shape your documents actually have, which is often not the shape you believe.

One framing to carry through. In a relational database you design for the data and query it however you like afterwards. In MongoDB you design for the queries. If you do not know the access patterns, you cannot design the documents - so the first question in any modelling exercise here is "what will read this, and how often?"

What you will be able to do

  • Explain BSON, its types, and where it differs from JSON in ways that matter
  • Use the CRUD and query operator surface, including array and nested-field queries
  • Decide between embedding and referencing from the access patterns, and defend it
  • Write and enforce a JSON Schema validator, and explain why "schemaless" is misleading
  • Build aggregation pipelines, including $lookup, $facet, $unwind and $group
  • Explain replica sets, elections and what a primary step-down does to an application
  • Choose read and write concerns per operation and state their guarantees
  • Use multi-document transactions, and explain why they are rarely the right answer
  • Consume change streams and build an event-driven feature on them
  • Design compound, multikey, TTL, partial and text indexes, and read explain output
  • Explain the working set and why it, not total data size, drives memory sizing
  • Choose a shard key and state what makes a bad one irreversible
  • Perform backup and restore and record a measured RPO and RTO
  • Implement RBAC, TLS and network restriction, and produce a cost checklist

What each level covers

5 levels · 7 lessons

  1. Beginner - Foundations

    Documents, BSON and the query surface; then the modelling decision the whole system rests on.

    2 lessons 11 min of reading

    Start with BSON, Collections and the CRUD Surface →
  2. Intermediate - Application Behaviour

    Replica sets, the concerns you choose per operation, transactions used sparingly, and change streams.

    1 lesson 7 min of reading

    Start with Replica Sets, Concerns, Transactions and Change Streams →
  3. Advanced - Performance and Reliability

    Indexes and the working set; then elections, sharding and the shard key you cannot take back.

    2 lessons 10 min of reading

    Start with Indexes, Explain Plans and Working Sets →
  4. Expert - Security and Production Architecture

    RBAC that is actually least privilege, TLS and network restriction, schema evolution without downtime, and connection pooling.

    1 lesson 7 min of reading

    Start with RBAC, TLS, Schema Evolution and Operations →
  5. Capstone

    One catalogue and order system, defended on correctness, measured performance, a survived failover and a stated cost.

    1 lesson 6 min of reading

    Start with Capstone - Product Catalogue with Faceted Search →

Guides and articles

Longer reading about this subject, written alongside the course.

Course guide How to work through this course Why Module 2 is the whole course, the one experiment to do properly, what Compass teaches, and what to skip. 3 min read

Before you start

  • MongoDB 7 or later, as a three-node replica set
  • mongosh, and optionally Compass
  • One programming language with an official MongoDB driver
  • The programme's shared foundations

Common questions

What does the MongoDB: Document Modeling and Operations course cover?
It is 5 levels and 7 lessons: Beginner - Foundations; Intermediate - Application Behaviour; Advanced - Performance and Reliability; Expert - Security and Production Architecture; Capstone. Each level ends with a quiz, and the last one is an exam over the whole course.
How long does it take?
About 41 minutes of reading and exercises - roughly 0.7 hours. It is self-paced with no cohort and no start date, so you can leave and come back and the site remembers where you were.
What do I need to know first?
MongoDB 7 or later, as a three-node replica set. mongosh, and optionally Compass. One programming language with an official MongoDB driver. The programme's shared foundations.
Is it free?
Yes. Every lesson, example and quiz in this course is free to read, and you do not need an account to read them. Signing in only adds progress tracking and quiz results.
What will I be able to do afterwards?
Explain BSON, its types, and where it differs from JSON in ways that matter. Use the CRUD and query operator surface, including array and nested-field queries. Decide between embedding and referencing from the access patterns, and defend it. Write and enforce a JSON Schema validator, and explain why "schemaless" is misleading. Build aggregation pipelines, including $lookup, $facet, $unwind and $group. Explain replica sets, elections and what a primary step-down does to an application. Choose read and write concerns per operation and state their guarantees. Use multi-document transactions, and explain why they are rarely the right answer. Consume change streams and build an event-driven feature on them. Design compound, multikey, TTL, partial and text indexes, and read explain output. Explain the working set and why it, not total data size, drives memory sizing. Choose a shard key and state what makes a bad one irreversible. Perform backup and restore and record a measured RPO and RTO. Implement RBAC, TLS and network restriction, and produce a cost checklist.