← Back to courses

Course

MongoDB

118 lessons across 8 modules

MongoDB from your first document to production: CRUD, data modeling, aggregation, indexes, Node.js with TypeScript and Mongoose, transactions, security, replication and sharding - and three real projects. Each lesson explains one idea in simple steps, with commands you can run and the real output.

Module 1 of 812 lessons3 ready

MongoDB Fundamentals

What MongoDB is, how it stores data, and your first database operations

Introduction to MongoDB

1.1

MongoDB is a document database: it stores data as JSON-like documents instead of rows in tables. Start a database, save three products of different shapes, find them again with mongosh, and read the same data from a Node.js program.

Beginnerfundamentals25 min
Lesson 1.1Open →

SQL vs NoSQL Databases

1.2

Store the same order twice: in SQL tables that need a JOIN, and as one MongoDB document. See what each does well - one read with no join, new fields without ALTER TABLE - and what it costs: no rules by default, and copied data that must be updated in many places.

Beginnerfundamentals30 min
Lesson 1.2Open →

MongoDB Use Cases and Limitations

1.3

Where MongoDB shines - catalogues, content, user profiles, events, real-time apps - and where it struggles. Then hit its real limits on purpose: the 16 MB document limit (on insert and when a document grows), the nesting limit, and a typo that silently hid a product.

Beginnerfundamentals25 min
Lesson 1.3Open →

Database, Collection, and Document

1.4

The three levels of storage, and how they map to SQL

A school: students, classes and teachers

Lesson 1.4planned

BSON and JSON

1.5

What MongoDB really stores, and the extra types BSON adds

Dates, decimals and ObjectIds that JSON cannot hold

Lesson 1.5planned

MongoDB Architecture Overview

1.6

mongod, mongosh, drivers, storage engine, replica sets and shards

The path of one query from your app to the disk

Lesson 1.6planned

Installing MongoDB Locally

1.7

Install the server and mongosh on macOS, Windows, Linux or Docker

Start mongod and connect for the first time

Lesson 1.7planned

Introduction to MongoDB Atlas

1.8

A free cloud cluster: create, allow your IP, connect

Your first database in the cloud

Lesson 1.8planned

Using MongoDB Compass

1.9

Browse, filter and edit data in the desktop app

Explore the shop products visually

Lesson 1.9planned

Creating and Managing Databases

1.10

use, show dbs, dropDatabase, and naming rules

Separate databases for dev and test

Lesson 1.10planned

Creating and Managing Collections

1.11

Implicit and explicit creation, options, rename and drop

A capped collection for recent logs

Lesson 1.11planned

Understanding the _id Field and ObjectId

1.12

What is inside an ObjectId, and choosing your own _id

Read the creation time from an ObjectId

Lesson 1.12planned
Module 2 of 820 lessonsComing soon

CRUD Operations and Data Modeling

Create, read, update and delete documents - and design them well

Inserting a Single Document

2.1

insertOne, the result, and duplicate _id errors

Add a new customer

Lesson 2.1planned

Inserting Multiple Documents

2.2

insertMany, ordered and unordered inserts

Import 1,000 products, with one bad one

Lesson 2.2planned

Finding Documents with find()

2.3

Filters, cursors and iterating results

All products in a category

Lesson 2.3planned

Retrieving a Single Document with findOne()

2.4

One document or null

Load a user by email

Lesson 2.4planned

Filtering Documents with Query Operators

2.5

$eq, $gt, $in and friends in a filter

Products between 10 and 50

Lesson 2.5planned

Selecting Fields with Projection

2.6

Include and exclude fields

A product list without descriptions

Lesson 2.6planned

Sorting Query Results

2.7

sort() by one or more fields

Cheapest first, then by name

Lesson 2.7planned

Limiting and Skipping Results

2.8

limit() and skip() for pages

Page 3 of the product list

Lesson 2.8planned

Updating Documents with updateOne()

2.9

$set, $unset, $inc and the update result

Change a price, count a view

Lesson 2.9planned

Updating Multiple Documents

2.10

updateMany and upserts

10% off a whole category

Lesson 2.10planned

Replacing Documents

2.11

replaceOne vs updateOne

Save an edited profile

Lesson 2.11planned

Deleting Documents

2.12

deleteOne, deleteMany and soft deletes

Remove expired sessions

Lesson 2.12planned

Updating Nested Documents and Arrays

2.13

Dot notation, $ and $[] positional operators

Change the qty of one order line

Lesson 2.13planned

Understanding Atomic Document Updates

2.14

One document changes all-or-nothing

Two buyers and the last item in stock

Lesson 2.14planned

Embedding vs Referencing

2.15

Store together, or link by id?

Order lines inside; customers outside

Lesson 2.15planned

One-to-One Relationships

2.16

Embed or split a one-to-one

A user and their settings

Lesson 2.16planned

One-to-Many Relationships

2.17

A few, many, or a huge number

A post and its comments

Lesson 2.17planned

Many-to-Many Relationships

2.18

Arrays of ids on one or both sides

Students and courses

Lesson 2.18planned

Schema Validation

2.19

$jsonSchema rules on a collection

Reject a product without a price

Lesson 2.19planned

Designing Documents for Real Applications

2.20

Design from the queries your app makes

A food delivery app, step by step

Lesson 2.20planned
Module 3 of 817 lessonsComing soon

Advanced Queries and Aggregation

Powerful queries, and pipelines that turn data into reports and features

Comparison Query Operators

3.1

$eq, $ne, $gt, $gte, $lt, $lte, $in, $nin

Orders over 1,000 from three cities

Lesson 3.1planned

Logical Query Operators

3.2

$and, $or, $not, $nor

In stock OR arriving this week

Lesson 3.2planned

Querying Nested Fields

3.3

Dot notation vs exact embedded matches

Customers in Hyderabad

Lesson 3.3planned

Querying Arrays

3.4

$all, $size, $elemMatch

Products tagged both "home" and "sale"

Lesson 3.4planned

Regular Expressions in Queries

3.5

$regex, options, and when it is slow

Names that start with "Sam"

Lesson 3.5planned

Array Update Operators

3.6

$push, $addToSet, $pull, $pop, $each, $slice

Keep the last 10 searches

Lesson 3.6planned

Introduction to Aggregation Pipelines

3.7

Stages that pass documents along

Revenue per category in one pipeline

Lesson 3.7planned

Filtering with $match

3.8

Filter early, use indexes

Only this month’s orders

Lesson 3.8planned

Reshaping Data with $project

3.9

Pick, rename and compute fields

Add a total field to each order

Lesson 3.9planned

Grouping Data with $group

3.10

$sum, $avg, $min, $max, $push

Sales per day

Lesson 3.10planned

Sorting and Limiting Aggregated Results

3.11

$sort, $limit, $skip in a pipeline

Top 5 customers

Lesson 3.11planned

Joining Collections with $lookup

3.12

Left outer joins in aggregation

Orders with their customer

Lesson 3.12planned

Unwinding Arrays with $unwind

3.13

One document per array item

Best-selling products from order lines

Lesson 3.13planned

Conditional Logic with $cond and $switch

3.14

If-else inside a pipeline

Label orders small, medium or large

Lesson 3.14planned

Pagination Strategies

3.15

skip/limit vs range (cursor) pagination

An infinite-scroll feed

Lesson 3.15planned

Building Reports with Aggregation

3.16

$facet, $bucket and dates

A monthly sales dashboard

Lesson 3.16planned

Aggregation Pipeline Optimization

3.17

Stage order, indexes, memory limits, explain

Make a slow report 10x faster

Lesson 3.17planned
Module 4 of 812 lessonsComing soon

Indexing and Performance

How MongoDB runs a query, and how indexes make it fast

Why Database Indexes Matter

4.1

Collection scans vs index scans

Find one email among 1,000,000 users

Lesson 4.1planned

Single-Field Indexes

4.2

createIndex on one field, ascending or descending

An index on email

Lesson 4.2planned

Compound Indexes

4.3

One index over several fields

Category + price

Lesson 4.3planned

Understanding Index Field Order

4.4

The ESR rule: Equality, Sort, Range

Why { price, category } was slower

Lesson 4.4planned

Multikey Indexes

4.5

Indexes on array fields

Fast search by tag

Lesson 4.5planned

Unique and Sparse Indexes

4.6

No duplicates; skip missing fields

One account per email

Lesson 4.6planned

Partial Indexes

4.7

Index only the documents that matter

Only active orders

Lesson 4.7planned

Text Indexes and Search

4.8

$text search and its limits; Atlas Search

Search product descriptions

Lesson 4.8planned

Understanding explain()

4.9

queryPlanner and executionStats

Is my query using an index?

Lesson 4.9planned

Reading Query Execution Plans

4.10

COLLSCAN, IXSCAN, FETCH, SORT; keys vs docs examined

Read three real plans

Lesson 4.10planned

Identifying Slow Queries

4.11

The profiler, slow query logs, Atlas tools

Find the slowest query of the day

Lesson 4.11planned

Index Trade-offs and Write Performance

4.12

Every index slows writes and uses memory

Insert speed with 0, 3 and 10 indexes

Lesson 4.12planned
Module 5 of 815 lessonsComing soon

Node.js, TypeScript, and Mongoose

Use MongoDB from real backend code, with types, models and tests

MongoDB Node.js Driver

5.1

What the driver does, installing it

Your first script with the driver

Lesson 5.1planned

Connecting Node.js to MongoDB

5.2

Connection strings, options, one client per app

Connect to local and Atlas

Lesson 5.2planned

Connection Pooling

5.3

How the pool reuses connections; maxPoolSize

100 requests, 10 connections

Lesson 5.3planned

CRUD Operations Using the Node.js Driver

5.4

insert, find, update, delete with async/await

A products module

Lesson 5.4planned

MongoDB TypeScript Types

5.5

Typed collections, ObjectId, Filter and UpdateFilter

Catch a wrong field name at compile time

Lesson 5.5planned

Introduction to Mongoose

5.6

An ODM: schemas and models on top of the driver

The same CRUD with Mongoose

Lesson 5.6planned

Defining Mongoose Schemas

5.7

Types, defaults, nested schemas, timestamps

A User schema

Lesson 5.7planned

Creating Mongoose Models

5.8

Models, documents, statics and methods

User.findByEmail()

Lesson 5.8planned

Schema Validation in Mongoose

5.9

Built-in and custom validators, errors

Reject a weak password

Lesson 5.9planned

Mongoose Middleware

5.10

pre and post hooks

Hash the password before save

Lesson 5.10planned

References and populate()

5.11

ref and populate, and its cost

Posts with their author

Lesson 5.11planned

Repository and Service Patterns

5.12

Keep database code in one place

A UserRepository and UserService

Lesson 5.12planned

Error Handling and Connection Failures

5.13

Duplicate keys, timeouts, reconnects

Stop the server mid-request

Lesson 5.13planned

Unit and Integration Testing

5.14

Mocks vs a real test database

Tests with mongodb-memory-server

Lesson 5.14planned

Building REST APIs with Express.js

5.15

Routes, validation and errors over MongoDB

A complete products API

Lesson 5.15planned
Module 6 of 812 lessonsComing soon

Transactions, Security, and Reliability

Keep data correct, keep it safe, and survive failures

Atomicity in MongoDB

6.1

What all-or-nothing means, per document

Half-done updates that cannot happen

Lesson 6.1planned

Single-Document Atomic Operations

6.2

findOneAndUpdate and conditional updates

Reserve the last seat safely

Lesson 6.2planned

Multi-Document Transactions

6.3

Changes across documents that succeed together

Move money between two accounts

Lesson 6.3planned

Transaction Sessions

6.4

startSession, withTransaction, retries

A transaction in Node.js

Lesson 6.4planned

Transaction Limitations and Trade-offs

6.5

Time limits, cost, and when to avoid them

Redesign to avoid a transaction

Lesson 6.5planned

MongoDB Authentication

6.6

Users, passwords and SCRAM

Turn on auth and create an app user

Lesson 6.6planned

Database Roles and Authorization

6.7

Built-in and custom roles, least privilege

A read-only reporting user

Lesson 6.7planned

Secure Connection Strings and Secrets

6.8

Environment variables, TLS, secret managers

No passwords in git

Lesson 6.8planned

Preventing Injection and Unsafe Queries

6.9

Operator injection and how to block it

A login bypass with { $ne: null }

Lesson 6.9planned

Schema Validation for Data Integrity

6.10

Strict validation levels and actions

Lock down an orders collection

Lesson 6.10planned

Write Concern and Read Concern

6.11

How sure is "saved"? How fresh is "read"?

w: "majority" vs w: 1

Lesson 6.11planned

Retryable Writes and Failure Handling

6.12

Automatic retries and idempotent design

A network blip during an insert

Lesson 6.12planned
Module 7 of 815 lessonsComing soon

Production, Replication, and Scaling

How MongoDB runs in production: copies, failover, sharding, backups and monitoring

MongoDB Replica Set Architecture

7.1

Several copies of the same data

A three-member replica set on one machine

Lesson 7.1planned

Primary and Secondary Nodes

7.2

Who takes writes, who copies

Write to the primary, read a secondary

Lesson 7.2planned

Replication and Oplog

7.3

How changes are copied

Read the oplog after an insert

Lesson 7.3planned

Automatic Failover

7.4

Elections when the primary dies

Kill the primary and watch

Lesson 7.4planned

Read Preferences

7.5

primary, secondary, nearest - and stale reads

Send reports to a secondary

Lesson 7.5planned

Sharding Fundamentals

7.6

Split data across servers

When one server is not enough

Lesson 7.6planned

Shard Keys

7.7

Choosing the field that splits the data

A good and a bad shard key

Lesson 7.7planned

Range-Based and Hashed Sharding

7.8

Two ways to spread data

Hot spots with a date key

Lesson 7.8planned

Sharded Cluster Architecture

7.9

mongos, config servers and shards

Follow one query through a cluster

Lesson 7.9planned

MongoDB Atlas Deployment

7.10

Tiers, regions, network access, backups

Deploy a production cluster

Lesson 7.10planned

Backup and Restore

7.11

mongodump/mongorestore and snapshots

Restore a deleted collection

Lesson 7.11planned

Monitoring and Database Metrics

7.12

serverStatus, mongostat, Atlas charts

Spot a problem before users do

Lesson 7.12planned

Dockerizing MongoDB Applications

7.13

Docker Compose for app + database

Node.js API and MongoDB in containers

Lesson 7.13planned

MongoDB in Microservices Architecture

7.14

Database per service, events, change streams

Orders and inventory services

Lesson 7.14planned

MongoDB vs PostgreSQL: Choosing the Right Database

7.15

An honest comparison, with examples

Three projects, three decisions

Lesson 7.15planned
Module 8 of 815 lessonsComing soon

Real-World Projects

Three projects, from beginner to advanced: a task API, a learning platform and a scalable product service

Task API: Project Setup and Requirements

8.1

Project 1 (beginner): requirements and setup

Express + TypeScript + MongoDB skeleton

Lesson 8.1planned

Task API: Task Document Design

8.2

Design the task document from the features

Status, due date, tags, owner

Lesson 8.2planned

Task API: CRUD API Implementation

8.3

Endpoints for every task action

Create, list, update, complete, delete

Lesson 8.3planned

Task API: Filtering, Pagination, and Validation

8.4

Query parameters to filters, safe pages

Overdue tasks, 20 per page

Lesson 8.4planned

Task API: Authentication and Testing

8.5

Users own tasks; integration tests

Only my tasks, tested

Lesson 8.5planned

LMS: Course and Lesson Data Modeling

8.6

Project 2 (intermediate): courses, modules, lessons

A course document and its lessons

Lesson 8.6planned

LMS: Modules, Enrollments, and Progress

8.7

Many-to-many enrollments and progress tracking

Mark a lesson complete

Lesson 8.7planned

LMS: Aggregation for Learning Analytics

8.8

Reports from progress data

Completion rate per course

Lesson 8.8planned

LMS: Indexing and Query Optimization

8.9

Index for the real queries

A dashboard from 2 s to 20 ms

Lesson 8.9planned

LMS: Role-Based Access and Integration Testing

8.10

Students, teachers, admins

Teachers see only their courses

Lesson 8.10planned

Product Service: Product and Inventory Data Modeling

8.11

Project 3 (advanced): products, variants, stock

A shirt with sizes and colours

Lesson 8.11planned

Product Service: Search, Filtering, and Aggregation

8.12

Faceted search and filters

Filter by brand, price and rating

Lesson 8.12planned

Product Service: Transactions and Inventory Consistency

8.13

Never sell stock you do not have

Two buyers, one item, a transaction

Lesson 8.13planned

Product Service: Caching, Performance, and Resilience

8.14

Cache, timeouts, retries

Survive a slow database

Lesson 8.14planned

Product Service: Docker Deployment, Monitoring, and Scaling

8.15

Ship it and watch it

Compose, metrics and a replica set

Lesson 8.15planned