MongoDB Mastery: all 66 lessons
Free MongoDB lessons from your first query to sharded clusters: CRUD, aggregation, indexes and explain(), schema design, transactions, replication, sharding, WiredTiger internals and operations. Every lesson has runnable examples in the interactive course.
Level 1: Beginner
Documents, BSON, mongosh and your first CRUD queries.
- What MongoDB is and when to use it · MongoDB Fundamentals · 15 minMongoDB stores data as documents: JSON-like records with nested objects and arrays. This lesson explains the model, how it differs from relational databases, and where it fits.
- Documents, collections and namespaces · MongoDB Fundamentals · 15 minThe rules every document follows: _id, field names, size limits, nesting, and how collections and databases are created.
- mongosh, connection strings and tools · mongosh & Tools · 18 minThe shell is a full JavaScript environment. Learn how to connect, navigate, read cursors, script, and which companion tools exist.
- mongosh configuration, scripting and legacy features to replace · mongosh & Tools · 20 minMake mongosh yours with config and .mongoshrc.js, run scripts safely from the command line with EJSON output, and replace the features that old code and old tutorials still use:…
- BSON types, ObjectId and type ordering · BSON Data Types · 18 minTypes decide how values compare, sort and index. Learn the important BSON types, how ObjectId works, and how MongoDB orders mixed types.
- insertOne, insertMany and bulk writes · Inserting Documents · 15 minCreate documents safely: generated ids, ordered versus unordered batches, duplicate key errors and the write result.
- Querying: equality, comparison and logic · Querying Documents · 20 minfind() with filters: equality, implicit AND, comparison operators, $in, $or, and querying nested fields with dot notation.
- Missing fields, null, $type, $regex and $expr · Querying Documents · 18 minThe subtle operators: how null matches missing fields, existence checks, pattern matching, and comparing two fields of the same document.
- Projection, sorting and pagination · Projection, Sort & Pagination · 20 minReturn only what you need, sort deterministically, and paginate without the skip trap.
- Cursors: batches, getMore, timeouts and tailable cursors · Projection, Sort & Pagination · 24 minA query does not return all its results at once. The server keeps a cursor and sends documents in batches. Learn how batches and getMore work, why cursors time out in the middle…
- Update operators, upserts and replacements · Updating & Deleting · 22 minModify documents atomically with update operators, create-or-update with upserts, and read the result counters correctly.
- Deleting data safely · Updating & Deleting · 12 mindeleteOne, deleteMany, drop, TTL expiry and soft deletes, plus a checklist for destructive operations in production.
Level 2: Intermediate
Arrays, aggregation, indexes, explain() and schema design.
- Querying arrays and embedded documents · Arrays & Embedded Documents · 20 minHow a condition on an array field matches any element, why that surprises people, and how $elemMatch, $all and $size give you precise control.
- Updating arrays: $push, $pull, positional operators · Arrays & Embedded Documents · 20 minAdd, remove and modify array elements in place, including the positional $, $[] and filtered $[id] operators.
- The aggregation pipeline: $match, $group, $project, $sort · Aggregation Pipeline · 25 minPipelines transform documents stage by stage. Build reports with $match, $group, $project, $sort, $limit and accumulators, and learn why stage order matters.
- Expressions: dates, strings and conditionals · Aggregation Pipeline · 18 minThe expression operators you will use every day: time bucketing, string manipulation, type conversion and null handling.
- $lookup, $unwind and $graphLookup · $lookup & Joins · 22 minJoin collections inside a pipeline, correlate with sub-pipelines, walk hierarchies with $graphLookup, and know when a join means your schema is wrong.
- $facet, $bucket, window functions, $merge and $out · Advanced Aggregation · 25 minMulti-faceted search results, histograms, running totals and rankings, and materialized views that refresh incrementally.
- Window functions with $setWindowFields · Advanced Aggregation · 25 minRunning totals, moving averages, rankings and period-over-period deltas computed over ordered partitions, without collapsing documents the way $group does.
- $unionWith, $densify and $fill · Advanced Aggregation · 22 minCombine documents from several collections into one pipeline, add the missing time slots to a series, and fill the gaps with a constant, the last known value or a straight line…
- Embedding vs referencing · Schema Design · 25 minDesign for how the application reads and writes. Learn the rules of thumb for embedding versus referencing based on relationship cardinality, growth and access patterns.
- Indexes: COLLSCAN vs IXSCAN · Indexes & explain() · 25 minWhat an index is physically, how a query uses it, and how to read explain() output to see whether it did.
- Reading explain() plans like a DBA · Indexes & explain() · 20 minGo beyond COLLSCAN vs IXSCAN: SORT stages, rejected plans, index bounds, and the verbosity modes.
- Compound indexes and the ESR rule · Compound Indexes & ESR · 30 minOrder the fields of a compound index as Equality, then Sort, then Range. Learn prefixes, covered queries and why one good compound index beats three single-field ones.
Level 3: Advanced
Transactions, concerns, change streams, validation, time series.
- Patterns for read performance: computed, subset, extended reference, bucket, outlier · Schema Design Patterns · 30 minThe schema design patterns that turn expensive reads into cheap ones by doing work at write time or by storing data in the shape it is read.
- Patterns for flexibility: polymorphic, attribute, versioning, trees, archive · Schema Design Patterns · 25 minModel varied shapes in one collection, index arbitrary attributes, evolve schemas without downtime, store hierarchies, and age out cold data.
- GridFS and storing large files · Schema Design Patterns · 20 minGridFS stores files larger than the 16 MB document limit by splitting them into chunks across two collections. Learn the layout, the indexes, how to check integrity, and when…
- Schema anti-patterns and tree structures · Schema Design Patterns · 26 minThe six schema anti-patterns from the MongoDB manual, how to detect each one on a running database, and the five ways to store a hierarchy: parent references, child references, an…
- Unique, partial, sparse, TTL, text, wildcard, hashed and geo indexes · Index Types & Options · 28 minEvery index type and option, what it is for, and the traps in each.
- Wildcard indexes for unpredictable fields · Index Types & Options · 18 minIndex every field under a path (or the whole document) when the queried fields are not known in advance, and understand the trade-offs versus the attribute pattern.
- Geospatial queries: 2dsphere, $near, $geoWithin and $geoNear · Index Types & Options · 22 minStore locations as GeoJSON, index them with 2dsphere, and answer nearest-store, within-radius and inside-polygon questions with correct units.
- The slow query workflow: profiler, logs, explain, fix · Query Optimization · 28 minA repeatable process for finding the queries that matter, diagnosing them, fixing them and proving the fix, as practised by DBAs on production systems.
- Multi-document transactions · Transactions · 28 minACID across documents and collections: sessions, the callback API, retries, write conflicts, limits and when not to use transactions.
- Write concern, read concern and read preference · Read & Write Concerns · 28 minTune durability, consistency and routing per operation: w and j, local/majority/snapshot/linearizable reads, primary/secondary routing and causal consistency.
- Change streams and resume tokens · Change Streams · 22 minSubscribe to inserts, updates, replaces and deletes in real time, filter them with a pipeline, and resume reliably after failures.
- Schema validation with $jsonSchema · Schema Validation · 20 minEnforce required fields, types, ranges and enumerations on the server, and roll validation out safely with validationLevel and validationAction.
- Time series, capped collections, TTL and views · Time Series & Special Collections · 22 minPurpose-built collection types: time series for measurements, capped for fixed-size logs, TTL for expiry, views for reusable read-only pipelines.
- Views, on-demand materialized views and collation · Time Series & Special Collections · 20 minExpose filtered or reshaped data through read-only views, precompute heavy reports with $merge, and make string matching and sorting language-aware and case-insensitive with…
- Clustered collections · Time Series & Special Collections · 18 minA clustered collection stores documents in _id order inside the _id index itself. Range reads on _id get faster, there is no separate _id index to maintain, and TTL can delete by…
Level 4: Database Engineer
WiredTiger, replica sets, oplog, backup, security, monitoring.
- WiredTiger: cache, eviction, checkpoints and the journal · WiredTiger Storage Engine · 30 minHow a write travels from a client to disk, why cache pressure is the root of many incidents, and which metrics tell you the storage engine is struggling.
- Maintenance and data checks: validate, compact, renameCollection and $redact · WiredTiger Storage Engine · 24 minCheck a collection and its indexes for corruption, get disk space back after large deletes, swap collections safely with renameCollection, and produce redacted copies of sensitive…
- Replica sets, elections and failover · Replica Sets & Elections · 32 minHow members replicate, how a new primary is elected, what priorities, votes, hidden and delayed members do, and how failover looks from the application.
- The oplog, initial sync, lag and rollback · Oplog & Replication · 28 minThe capped collection at the heart of replication: what entries look like, how big it should be, what causes replication lag and how rollback works.
- Backup, restore and point-in-time recovery · Backup & Restore · 30 minLogical versus physical backups, consistent snapshots, oplog-based point-in-time recovery, and the restore drills that prove it all works.
- Percona Backup for MongoDB: logical, physical and PITR · Backup & Restore · 25 minRun consistent backups of replica sets and sharded clusters with PBM, enable point-in-time recovery from oplog slices, and rehearse restores.
- Security: authentication, RBAC, TLS and encryption · Security · 28 minHarden a self-managed deployment: enable auth, least-privilege roles, TLS everywhere, internal authentication, encryption at rest, field-level encryption and auditing.
- Client-side field level encryption and Queryable Encryption · Security · 22 minEncrypt sensitive fields in the driver so the server, backups and DBAs only ever see ciphertext, and know what you can still query.
- LDAP, Kerberos and x.509 authentication · Security · 24 minConnect self-hosted MongoDB to corporate identity: authenticate users against LDAP or Kerberos, map directory groups to MongoDB roles, and use x.509 certificates for services.…
- Monitoring and diagnostics · Monitoring & Diagnostics · 30 minThe metrics that matter, how to read serverStatus, currentOp, logs and FTDC, and a triage order for incidents.
- Monitoring with Percona Monitoring and Management (PMM) · Monitoring & Diagnostics · 20 minDeploy PMM Server and agents, add MongoDB services with the right user, and use the dashboards and Query Analytics to find bottlenecks.
- Server logs: structured JSON, verbosity and log rotation · Monitoring & Diagnostics · 22 minmongod writes one JSON document per log line. Learn to read the fields, find slow queries and errors, raise verbosity for one component without flooding the disk, and rotate logs…
- Rolling upgrades and featureCompatibilityVersion · Upgrades & FCV · 22 minUpgrade replica sets and sharded clusters without downtime, use FCV as the safety latch, and plan the rollback path.
Level 5: Database Architect
Sizing, drivers and pooling, production tuning, HA/DR, Kubernetes.
- Capacity planning: working set, RAM, disk and IOPS · Capacity Planning & Sizing · 28 minEstimate the hardware a workload needs, from document counts and access patterns to RAM for the working set, disk for growth and IOPS for writes.
- Drivers, connection pools, timeouts and retries · Drivers & Connection Pooling · 26 minConfigure the application side correctly: one client per process, pool sizing, server selection and timeouts, retryable writes, and avoiding connection storms.
- Production host tuning: OS, filesystem, memory and limits · Production Tuning · 22 minThe operating system settings from the production notes that prevent latency spikes and outages on self-managed hosts.
- HA, DR and multi-region topologies · HA, DR & Multi-Region · 30 minDesign for data-centre and region failures: member placement, majority math, disaster recovery runbooks, forced reconfiguration and RPO/RTO trade-offs.
- MongoDB on Kubernetes with operators · MongoDB on Kubernetes · 28 minRun replica sets and sharded clusters on Kubernetes: operators, StatefulSets, storage, scheduling, networking, backups and day-2 operations.
- Percona Operator for MongoDB in practice · MongoDB on Kubernetes · 25 minDeploy replica sets and sharded clusters with the PerconaServerMongoDB custom resource, wire in PBM backups, and run day-2 operations safely.
- How to answer MongoDB interview questions · Interview Preparation · 20 minA structure for technical answers, what interviewers listen for at each level, and how to use the rest of this site to prepare.
Level 6: Sharding / Distributed
Sharded clusters, shard keys, balancer, resharding, migrations.
- Sharded cluster architecture and query routing · Sharding Architecture · 28 minmongos routers, the config server replica set and shards; how queries are targeted or broadcast, and what changes for applications.
- Choosing a shard key: cardinality, frequency, monotonicity · Shard Keys · 32 minThe decision that is hardest to change. Evaluate candidate keys against write distribution, query targeting and growth, and compare hashed, ranged and compound keys in the…
- Chunks, balancer, zones and orphans · Chunks, Balancer & Resharding · 25 minHow data moves between shards, how to control when it moves, how to pin data to locations with zones, and what orphaned documents are.
- Sharding operations in 7.0 and 8.0 · Chunks, Balancer & Resharding · 26 minHow sharded clusters are run today: the balancer by data size, no automatic splitting, the AutoMerger and defragmentation that keep the chunk count low, moving and unsharding…
- Cluster migrations and cutover · Cluster Migrations · 25 minMove data between clusters, versions, topologies or data centres with minimal downtime: dump/restore, replica set extension, mongosync and CDC-based approaches, with validation…
Level 7: Search + Vector
Text search, vector search and RAG patterns with MongoDB.
- Text indexes, $text and full-text search engines · Text Search · 22 minKeyword search with the built-in text index (stemming, stop words, phrases, negation, weights) and when you need a Lucene-based search engine instead.
- Vector search and RAG with MongoDB · Vector Search & RAG · 30 minStore embeddings next to your documents, index them for approximate nearest neighbour search, combine semantic similarity with filters, and build retrieval-augmented generation.