Most MongoDB tutorials end where the hard problems begin: the basics of CRUD feel approachable, but the day you need to explain why a query is slow, choose a shard key, or recover from a bad write at 2am — that’s when the gaps show.
This series fills those gaps. It is built around the decisions and trade-offs that production deployments force on you, not a walkthrough of the driver API. The examples are in Python and PyMongo throughout — not because other stacks don’t matter, but because concrete code is clearer than pseudo-code, and the patterns generalise directly.
The eleven parts
-
Indexes deep dive — compound vs single-field, the ESR rule, what a “covered query” actually means, and the Python snippets that make the difference visible in
explain(). -
Reading execution plans —
explain()output anatomy, how to tell a healthy plan from a slow one, theFETCHstage and what to do about it, and the one metric people misread. -
Write concerns & read concerns — what
w:"majority"withj:trueactually guarantees, the voting-node detail that bites operators, and whenlinearizableread concern is worth its latency. -
Replica sets & elections — heartbeats, the pv1 election protocol, the pre-vote phase, what happens second-by-second when the primary dies, and what retryable writes do (and don’t) cover.
-
Read preferences — the five modes,
maxStalenessSecondsand its 90-second floor, the read-your-own-writes trap withnearest, and Python configuration that gets each scenario right. -
Aggregation pipeline for ops —
$lookup,$group,$mergevs$out, the 100 MB per-stage RAM limit,allowDiskUse, and why$outis right for nightly rebuilds and$mergeis right for incremental updates. -
Sharding architecture — ranged vs hashed shard keys, why a timestamp shard key is a hotspot waiting to happen, compound keys that solve both problems, jumbo chunks and how to resolve them.
-
Change streams & oplog tailing —
watch()and resume tokens, the at-least-once delivery pattern (and why save-before-process is the wrong call),startAtOperationTime, and the oplog window caveat. -
Backup & point-in-time recovery —
mongodump --oplog,mongorestore --oplogReplay --oplogLimit, what logical backup silently misses that a filesystem snapshot captures, and the sharded-cluster caveat. -
Monitoring & security hardening — the four signals to check when latency spikes,
$currentOp, the database profiler, WiredTiger cache eviction, and the minimum-privilege RBAC pattern for a Python service. -
Under the hood: WiredTiger storage — B-trees and RecordIds, copy-on-write pages, the 60-second checkpoint plus journal durability model, compression, and document-level concurrency — the machinery every earlier part stands on.
How to read it
Parts 1–2 are the foundation. If you can read an explain() output and
know what an ESR violation means, every performance conversation you have about
MongoDB will be more concrete. Don’t skip them even if they feel familiar.
Parts 3–5 are the distributed-systems layer: durability, consistency, and where reads come from. This is where most “mysterious data-loss” and “stale read” incidents live.
Parts 6–7 are scale: aggregation that doesn’t OOM, and sharding that doesn’t create hotspots. Part 6 is relevant long before you shard; Part 7 matters the moment you do.
Parts 8–10 are the operational muscle: real-time event processing that survives crashes, backup that works under pressure, and observability tight enough to diagnose a latency spike before the second PagerDuty alert fires.
Everything version-sensitive here was checked against MongoDB 9.0 (current stable as of late 2026). Core concepts are stable across 7.x, 8.x, and 9.x. Start with Part 1.