MongoDB: Document Modeling and Operations
Embedding against referencing, aggregation pipelines, replica sets and sharding - and the schema design that decides everything else.
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
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
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
-
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 → -
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 → -
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 → -
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 → -
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.
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.