Skip to main content
Databases

MongoDB Tutorial with Examples.

MongoDB tutorial for document databases: aggregation pipelines, indexing, change streams and Atlas cloud patterns.

Beginner

Start here — no prior experience needed

1 lesson

Intermediate

For developers with core concepts down

6 lessons
mongodb intermediate
5 min read

Embed reviews inside a book document and push 50,000 of them in — the document balloons to 5.9MB and fetching it goes from 2ms to 102ms. Moving to a referenced collection brings the fetch back to 3ms.

mongodb intermediate
5 min read

A query against 200,000 documents takes 65ms and scans every single one without an index. One index later it's 2ms. A covered query on top of that touches zero documents at all — explain() proves each claim.

mongodb intermediate
5 min read

$limit before $sort doesn't error — it just silently returns the wrong documents. $match, $group, $sort, $limit, and $lookup, and the one ordering mistake that returns confidently wrong data.

mongodb intermediate
5 min read

A $match placed after $group looks like it must scan everything first — but MongoDB's optimizer can rewrite it into a pure index lookup when filtering on the group key itself. Filter on a computed value like a $sum, and that optimization disappears entirely.

mongodb intermediate
5 min read

watch() fails outright on a standalone server — change streams need a replica set, even a local one. Once that's running: real insert/update/delete events, filtering by operation type, and resuming after a disconnect.

mongodb intermediate
5 min read

Transfer money between two accounts as a single atomic transaction — then abort one on purpose and prove the balance actually rolls back, not just that the code stopped running.

Advanced

Production-grade patterns for experienced engineers

3 lessons

Also part of MongoDB

Taught in other topics. Each link opens the lesson in its home topic.

1 lesson