MongoDB Mastery

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 min
    MongoDB 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 min
    The 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 min
    The 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 min
    Make 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 min
    Types 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 min
    Create documents safely: generated ids, ordered versus unordered batches, duplicate key errors and the write result.
  • Querying: equality, comparison and logic · Querying Documents · 20 min
    find() 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 min
    The 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 min
    Return only what you need, sort deterministically, and paginate without the skip trap.
  • Cursors: batches, getMore, timeouts and tailable cursors · Projection, Sort & Pagination · 24 min
    A 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 min
    Modify documents atomically with update operators, create-or-update with upserts, and read the result counters correctly.
  • Deleting data safely · Updating & Deleting · 12 min
    deleteOne, 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 min
    How 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 min
    Add, remove and modify array elements in place, including the positional $, $[] and filtered $[id] operators.
  • The aggregation pipeline: $match, $group, $project, $sort · Aggregation Pipeline · 25 min
    Pipelines 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 min
    The expression operators you will use every day: time bucketing, string manipulation, type conversion and null handling.
  • $lookup, $unwind and $graphLookup · $lookup & Joins · 22 min
    Join 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 min
    Multi-faceted search results, histograms, running totals and rankings, and materialized views that refresh incrementally.
  • Window functions with $setWindowFields · Advanced Aggregation · 25 min
    Running 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 min
    Combine 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 min
    Design 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 min
    What 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 min
    Go beyond COLLSCAN vs IXSCAN: SORT stages, rejected plans, index bounds, and the verbosity modes.
  • Compound indexes and the ESR rule · Compound Indexes & ESR · 30 min
    Order 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.

Level 4: Database Engineer

WiredTiger, replica sets, oplog, backup, security, monitoring.

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 min
    Estimate 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 min
    Configure 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 min
    The 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 min
    Design 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 min
    Run 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 min
    Deploy 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 min
    A 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 min
    mongos 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 min
    The 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 min
    How 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 min
    How 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 min
    Move 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 min
    Keyword 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 min
    Store embeddings next to your documents, index them for approximate nearest neighbour search, combine semantic similarity with filters, and build retrieval-augmented generation.