Free course · 11 lessons · Beginner

MongoDB from Basics to Production

Learn MongoDB from documents and queries to production: CRUD with update operators, query operators and projections, data modelling with embedding and references, indexes and explain, the aggregation pipeline, schema validation, multi-document transactions, keyset pagination and the bucket pattern, application code with PyMongo, TTL indexes, change streams and write concerns. Every example was run against MongoDB 9.0.

Start the course

1. MongoDB Basics

Documents and CRUD, query operators and projections, modelling data with embedding and references, indexes and explain, and the aggregation pipeline.

  1. Documents and CRUD Operations — Insert, find, update and delete documents with the MongoDB shell, using update operators and upserts instead of replacing whole documents.
  2. Query Operators, Projections and Sorting — Filter documents with comparison, logical, array and regex operators, return only needed fields, and sort and limit results.
  3. Data Modelling: Embedding or Referencing — Design documents around access patterns: embed data read together, reference data that grows or is shared, and join with $lookup when needed.
  4. Indexes and explain() — Create single-field and compound indexes, order compound keys with the equality-sort-range rule, and verify query plans with explain.
  5. The Aggregation Pipeline — Analyse data on the server with $match, $group, $project, $unwind, $sort and $facet stages, in the right order for performance.

2. MongoDB in Production

Schema validation, multi-document transactions, pagination and bounded arrays, application code with the Python driver, and TTL indexes, change streams and write concerns.

  1. Schema Validation with $jsonSchema — Enforce required fields, types, formats and allowed values at the database level with collection validators, and roll them out safely.
  2. Multi-Document Transactions — Update several documents atomically with sessions and transactions, handle aborts, and know when single-document atomicity is enough.
  3. Pagination and Bounded Arrays — Paginate large collections with range queries instead of skip, and replace ever-growing arrays with a bucket pattern.
  4. Application Code with the Python Driver — Use PyMongo from an application: one client per process, write concerns, unique indexes with duplicate-key handling, bulk writes and timeouts.
  5. TTL Indexes, Change Streams and Write Concern — Expire documents automatically with TTL indexes, react to changes in real time with change streams, and choose durability with write and read concerns.

3. Capstone

Design a MongoDB data layer.

  1. Capstone: Design the Data Layer for Event Ticketing — Design MongoDB collections, indexes, consistency and operations for a ticketing platform with flash sales and seat reservations.

Was this page helpful?