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.
MongoDB Fundamentals
What MongoDB is, how it stores data, and your first database operations
Introduction to MongoDB
1.1MongoDB 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.
SQL vs NoSQL Databases
1.2Store 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.
MongoDB Use Cases and Limitations
1.3Where 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.
Database, Collection, and Document
1.4The three levels of storage, and how they map to SQL
A school: students, classes and teachers
BSON and JSON
1.5What MongoDB really stores, and the extra types BSON adds
Dates, decimals and ObjectIds that JSON cannot hold
MongoDB Architecture Overview
1.6mongod, mongosh, drivers, storage engine, replica sets and shards
The path of one query from your app to the disk
Installing MongoDB Locally
1.7Install the server and mongosh on macOS, Windows, Linux or Docker
Start mongod and connect for the first time
Introduction to MongoDB Atlas
1.8A free cloud cluster: create, allow your IP, connect
Your first database in the cloud
Using MongoDB Compass
1.9Browse, filter and edit data in the desktop app
Explore the shop products visually
Creating and Managing Databases
1.10use, show dbs, dropDatabase, and naming rules
Separate databases for dev and test
Creating and Managing Collections
1.11Implicit and explicit creation, options, rename and drop
A capped collection for recent logs
Understanding the _id Field and ObjectId
1.12What is inside an ObjectId, and choosing your own _id
Read the creation time from an ObjectId
CRUD Operations and Data Modeling
Create, read, update and delete documents - and design them well
Inserting a Single Document
2.1insertOne, the result, and duplicate _id errors
Add a new customer
Inserting Multiple Documents
2.2insertMany, ordered and unordered inserts
Import 1,000 products, with one bad one
Finding Documents with find()
2.3Filters, cursors and iterating results
All products in a category
Retrieving a Single Document with findOne()
2.4One document or null
Load a user by email
Filtering Documents with Query Operators
2.5$eq, $gt, $in and friends in a filter
Products between 10 and 50
Selecting Fields with Projection
2.6Include and exclude fields
A product list without descriptions
Sorting Query Results
2.7sort() by one or more fields
Cheapest first, then by name
Limiting and Skipping Results
2.8limit() and skip() for pages
Page 3 of the product list
Updating Documents with updateOne()
2.9$set, $unset, $inc and the update result
Change a price, count a view
Updating Multiple Documents
2.10updateMany and upserts
10% off a whole category
Replacing Documents
2.11replaceOne vs updateOne
Save an edited profile
Deleting Documents
2.12deleteOne, deleteMany and soft deletes
Remove expired sessions
Updating Nested Documents and Arrays
2.13Dot notation, $ and $[] positional operators
Change the qty of one order line
Understanding Atomic Document Updates
2.14One document changes all-or-nothing
Two buyers and the last item in stock
Embedding vs Referencing
2.15Store together, or link by id?
Order lines inside; customers outside
One-to-One Relationships
2.16Embed or split a one-to-one
A user and their settings
One-to-Many Relationships
2.17A few, many, or a huge number
A post and its comments
Many-to-Many Relationships
2.18Arrays of ids on one or both sides
Students and courses
Schema Validation
2.19$jsonSchema rules on a collection
Reject a product without a price
Designing Documents for Real Applications
2.20Design from the queries your app makes
A food delivery app, step by step
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
Logical Query Operators
3.2$and, $or, $not, $nor
In stock OR arriving this week
Querying Nested Fields
3.3Dot notation vs exact embedded matches
Customers in Hyderabad
Querying Arrays
3.4$all, $size, $elemMatch
Products tagged both "home" and "sale"
Regular Expressions in Queries
3.5$regex, options, and when it is slow
Names that start with "Sam"
Array Update Operators
3.6$push, $addToSet, $pull, $pop, $each, $slice
Keep the last 10 searches
Introduction to Aggregation Pipelines
3.7Stages that pass documents along
Revenue per category in one pipeline
Filtering with $match
3.8Filter early, use indexes
Only this month’s orders
Reshaping Data with $project
3.9Pick, rename and compute fields
Add a total field to each order
Grouping Data with $group
3.10$sum, $avg, $min, $max, $push
Sales per day
Sorting and Limiting Aggregated Results
3.11$sort, $limit, $skip in a pipeline
Top 5 customers
Joining Collections with $lookup
3.12Left outer joins in aggregation
Orders with their customer
Unwinding Arrays with $unwind
3.13One document per array item
Best-selling products from order lines
Conditional Logic with $cond and $switch
3.14If-else inside a pipeline
Label orders small, medium or large
Pagination Strategies
3.15skip/limit vs range (cursor) pagination
An infinite-scroll feed
Building Reports with Aggregation
3.16$facet, $bucket and dates
A monthly sales dashboard
Aggregation Pipeline Optimization
3.17Stage order, indexes, memory limits, explain
Make a slow report 10x faster
Indexing and Performance
How MongoDB runs a query, and how indexes make it fast
Why Database Indexes Matter
4.1Collection scans vs index scans
Find one email among 1,000,000 users
Single-Field Indexes
4.2createIndex on one field, ascending or descending
An index on email
Compound Indexes
4.3One index over several fields
Category + price
Understanding Index Field Order
4.4The ESR rule: Equality, Sort, Range
Why { price, category } was slower
Multikey Indexes
4.5Indexes on array fields
Fast search by tag
Unique and Sparse Indexes
4.6No duplicates; skip missing fields
One account per email
Partial Indexes
4.7Index only the documents that matter
Only active orders
Text Indexes and Search
4.8$text search and its limits; Atlas Search
Search product descriptions
Understanding explain()
4.9queryPlanner and executionStats
Is my query using an index?
Reading Query Execution Plans
4.10COLLSCAN, IXSCAN, FETCH, SORT; keys vs docs examined
Read three real plans
Identifying Slow Queries
4.11The profiler, slow query logs, Atlas tools
Find the slowest query of the day
Index Trade-offs and Write Performance
4.12Every index slows writes and uses memory
Insert speed with 0, 3 and 10 indexes
Node.js, TypeScript, and Mongoose
Use MongoDB from real backend code, with types, models and tests
MongoDB Node.js Driver
5.1What the driver does, installing it
Your first script with the driver
Connecting Node.js to MongoDB
5.2Connection strings, options, one client per app
Connect to local and Atlas
Connection Pooling
5.3How the pool reuses connections; maxPoolSize
100 requests, 10 connections
CRUD Operations Using the Node.js Driver
5.4insert, find, update, delete with async/await
A products module
MongoDB TypeScript Types
5.5Typed collections, ObjectId, Filter and UpdateFilter
Catch a wrong field name at compile time
Introduction to Mongoose
5.6An ODM: schemas and models on top of the driver
The same CRUD with Mongoose
Defining Mongoose Schemas
5.7Types, defaults, nested schemas, timestamps
A User schema
Creating Mongoose Models
5.8Models, documents, statics and methods
User.findByEmail()
Schema Validation in Mongoose
5.9Built-in and custom validators, errors
Reject a weak password
Mongoose Middleware
5.10pre and post hooks
Hash the password before save
References and populate()
5.11ref and populate, and its cost
Posts with their author
Repository and Service Patterns
5.12Keep database code in one place
A UserRepository and UserService
Error Handling and Connection Failures
5.13Duplicate keys, timeouts, reconnects
Stop the server mid-request
Unit and Integration Testing
5.14Mocks vs a real test database
Tests with mongodb-memory-server
Building REST APIs with Express.js
5.15Routes, validation and errors over MongoDB
A complete products API
Transactions, Security, and Reliability
Keep data correct, keep it safe, and survive failures
Atomicity in MongoDB
6.1What all-or-nothing means, per document
Half-done updates that cannot happen
Single-Document Atomic Operations
6.2findOneAndUpdate and conditional updates
Reserve the last seat safely
Multi-Document Transactions
6.3Changes across documents that succeed together
Move money between two accounts
Transaction Sessions
6.4startSession, withTransaction, retries
A transaction in Node.js
Transaction Limitations and Trade-offs
6.5Time limits, cost, and when to avoid them
Redesign to avoid a transaction
MongoDB Authentication
6.6Users, passwords and SCRAM
Turn on auth and create an app user
Database Roles and Authorization
6.7Built-in and custom roles, least privilege
A read-only reporting user
Secure Connection Strings and Secrets
6.8Environment variables, TLS, secret managers
No passwords in git
Preventing Injection and Unsafe Queries
6.9Operator injection and how to block it
A login bypass with { $ne: null }
Schema Validation for Data Integrity
6.10Strict validation levels and actions
Lock down an orders collection
Write Concern and Read Concern
6.11How sure is "saved"? How fresh is "read"?
w: "majority" vs w: 1
Retryable Writes and Failure Handling
6.12Automatic retries and idempotent design
A network blip during an insert
Production, Replication, and Scaling
How MongoDB runs in production: copies, failover, sharding, backups and monitoring
MongoDB Replica Set Architecture
7.1Several copies of the same data
A three-member replica set on one machine
Primary and Secondary Nodes
7.2Who takes writes, who copies
Write to the primary, read a secondary
Replication and Oplog
7.3How changes are copied
Read the oplog after an insert
Automatic Failover
7.4Elections when the primary dies
Kill the primary and watch
Read Preferences
7.5primary, secondary, nearest - and stale reads
Send reports to a secondary
Sharding Fundamentals
7.6Split data across servers
When one server is not enough
Shard Keys
7.7Choosing the field that splits the data
A good and a bad shard key
Range-Based and Hashed Sharding
7.8Two ways to spread data
Hot spots with a date key
Sharded Cluster Architecture
7.9mongos, config servers and shards
Follow one query through a cluster
MongoDB Atlas Deployment
7.10Tiers, regions, network access, backups
Deploy a production cluster
Backup and Restore
7.11mongodump/mongorestore and snapshots
Restore a deleted collection
Monitoring and Database Metrics
7.12serverStatus, mongostat, Atlas charts
Spot a problem before users do
Dockerizing MongoDB Applications
7.13Docker Compose for app + database
Node.js API and MongoDB in containers
MongoDB in Microservices Architecture
7.14Database per service, events, change streams
Orders and inventory services
MongoDB vs PostgreSQL: Choosing the Right Database
7.15An honest comparison, with examples
Three projects, three decisions
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.1Project 1 (beginner): requirements and setup
Express + TypeScript + MongoDB skeleton
Task API: Task Document Design
8.2Design the task document from the features
Status, due date, tags, owner
Task API: CRUD API Implementation
8.3Endpoints for every task action
Create, list, update, complete, delete
Task API: Filtering, Pagination, and Validation
8.4Query parameters to filters, safe pages
Overdue tasks, 20 per page
Task API: Authentication and Testing
8.5Users own tasks; integration tests
Only my tasks, tested
LMS: Course and Lesson Data Modeling
8.6Project 2 (intermediate): courses, modules, lessons
A course document and its lessons
LMS: Modules, Enrollments, and Progress
8.7Many-to-many enrollments and progress tracking
Mark a lesson complete
LMS: Aggregation for Learning Analytics
8.8Reports from progress data
Completion rate per course
LMS: Indexing and Query Optimization
8.9Index for the real queries
A dashboard from 2 s to 20 ms
LMS: Role-Based Access and Integration Testing
8.10Students, teachers, admins
Teachers see only their courses
Product Service: Product and Inventory Data Modeling
8.11Project 3 (advanced): products, variants, stock
A shirt with sizes and colours
Product Service: Search, Filtering, and Aggregation
8.12Faceted search and filters
Filter by brand, price and rating
Product Service: Transactions and Inventory Consistency
8.13Never sell stock you do not have
Two buyers, one item, a transaction
Product Service: Caching, Performance, and Resilience
8.14Cache, timeouts, retries
Survive a slow database
Product Service: Docker Deployment, Monitoring, and Scaling
8.15Ship it and watch it
Compose, metrics and a replica set