MongoDB
Store, query and aggregate documents from Node with the official driver API, running against a real-behaving database in every lesson.
32 lessons across 8 units: documents and BSON, queries, updates, the aggregation pipeline, data modeling and $lookup, indexes, MongoDB in Node apps, and an Express API on MongoDB, with 64 runnable examples, quizzes and 32 coding problems.
- Units
- 8
- Lessons
- 32
- Coding problems
- 32
- Examples
- 64
Free: units 1 to 2 (9 lessons). Units 3 to 8 with DevArcade Pro.
What you'll learn
- Documents and CollectionsWhat a document database is, connecting from Node, BSON types and ObjectIds, and inserting documents.
- QueryingFilters, comparison and logical operators, nested fields and arrays, projection, sorting and paging.
- Updating and DeletingUpdate operators, array updates and positional operators, upserts and replacement, findOneAndUpdate and deletes.
- The Aggregation PipelineStages, $group and accumulators, $unwind, expressions and $addFields, $facet and $bucket.
- Data ModelingEmbedding or referencing, $lookup joins, schema design patterns, and schema validation.
- Indexes and PerformanceIndexes and explain(), unique indexes and duplicate keys, compound indexes and the ESR rule.
- MongoDB in Node AppsRepository modules and ids, handling driver errors, transactions, and paging large collections.
- An Express API on MongoDBRoutes over collections, operator injection, and the bookmarks API boss.
Course outline
8 units and 32 lessons. Each lesson has a short read with examples you run, a quiz, and coding problems tested in your browser; most have a step-through visualizer.
- Free
Unit 1:Documents and Collections
What a document database is, connecting from Node, BSON types and ObjectIds, and inserting documents.
- What MongoDB Is A document database: databases hold collections, collections hold JSON-like documents, and documents can nest objects and arrays.1 problem
- Connecting from Node MongoClient and connection strings, picking a database and collections, one client per process, and closing it when you are done.1 problem
- Documents, BSON and ObjectId BSON types beyond JSON (dates, ObjectIds, integers and doubles), the _id field, what an ObjectId contains, and field names to avoid.1 problem
- Inserting Documents insertOne and insertMany, the generated _id, duplicate key errors, and ordered versus unordered bulk inserts.1 problem
-
- Free
Unit 2:Querying
Filters, comparison and logical operators, nested fields and arrays, projection, sorting and paging.
- Finding Documents find and findOne, filters as objects, several fields meaning AND, cursors and toArray, and counting with countDocuments.1 problem
- Comparison Operators Ranges with $gt, $gte, $lt and $lte, $ne, and lists with $in and $nin; how comparisons treat different types and missing fields.1 problem
- OR, NOT and Missing Fields Combine conditions with $or, $and, $nor and $not, test for fields with $exists, and how null matches both null and missing.1 problem
- Nested Fields and Arrays Dot notation for embedded documents, how a filter on an array field matches any element, $all and $size, and $elemMatch for several conditions on one element.1 problem
- Projection, Sorting and Paging Return only the fields you need, sort by one or more fields, page with skip and limit, count with countDocuments and list values with distinct.1 problem
-
- Pro
Unit 3:Updating and Deleting
Update operators, array updates and positional operators, upserts and replacement, findOneAndUpdate and deletes.
- Update Operators updateOne and updateMany with $set, $unset, $inc, $mul, $min, $max and $rename, what matchedCount and modifiedCount mean, and why updates are atomic.1 problem
- Updating Arrays $push with $each, $sort and $slice, $addToSet, $pull and $pop, and the positional operators $ and $[] for changing elements in place.1 problem
- Upserts and Replacing Documents Insert-or-update in one call with upsert, initialize new documents with $setOnInsert, and replace whole documents with replaceOne.1 problem
- findOneAndUpdate and Deleting Change a document and get it back in one atomic step (counters, job queues), and remove documents with deleteOne, deleteMany and findOneAndDelete.1 problem
-
- Pro
Unit 4:The Aggregation Pipeline
Stages, $group and accumulators, $unwind, expressions and $addFields, $facet and $bucket.
- The Aggregation Pipeline aggregate() runs documents through a list of stages: $match, $project, $sort, $limit, $skip and $count, and why $match goes first.1 problem
- Grouping with $group One output document per key: accumulators $sum, $avg, $min, $max, $first, $last, $push and $addToSet, grouping by several fields or by nothing.1 problem
- Arrays in Pipelines: $unwind Turn each array element into its own document to group by it: order lines, tags, and keeping documents with empty arrays.1 problem
- Expressions and $addFields Computed fields with $addFields: arithmetic, strings, dates, conditions with $cond and $switch, defaults with $ifNull, and array expressions like $filter and $map.1 problem
- Facets, Buckets and Search Pages Run several sub-pipelines over the same documents with $facet (a page plus its total and filters), group ranges with $bucket, and count values with $sortByCount.1 problem
-
- Pro
Unit 5:Data Modeling
Embedding or referencing, $lookup joins, schema design patterns, and schema validation.
- Embed or Reference? The central modeling choice: embed data that is read together and owned by one parent, reference data that is shared, large or unbounded. Design for your queries.1 problem
- Joining with $lookup Pull referenced documents into a pipeline with $lookup (local and foreign fields, or a sub-pipeline), then $unwind or count the matches.1 problem
- Schema Design Patterns Proven shapes for common problems: the computed pattern (keep totals up to date on write), the subset pattern (embed the latest few), the extended reference and the bucket pattern.1 problem
- Schema Validation Flexible does not mean unchecked: attach a $jsonSchema validator to a collection, read error 121, and choose validation levels and actions for existing data.1 problem
-
- Pro
Unit 6:Indexes and Performance
Indexes and explain(), unique indexes and duplicate keys, compound indexes and the ESR rule.
- Indexes and explain() Why a query without an index reads every document (COLLSCAN), how createIndex changes that (IXSCAN), and reading explain() output: keys and documents examined.1 problem
- Unique Indexes Enforce uniqueness in the database (emails, usernames, slugs), handle error 11000 as a 409 Conflict, normalize values first, and use partial or sparse indexes for optional fields.1 problem
- Compound Indexes and the ESR Rule Indexes on several fields: why order matters, prefixes, the Equality-Sort-Range rule, multikey indexes on arrays, and TTL indexes that expire documents.1 problem
-
- Pro
Unit 7:MongoDB in Node Apps
Repository modules and ids, handling driver errors, transactions, and paging large collections.
- A Repository Module Keep database code in one module: inject the db, turn string ids into ObjectIds at the edge, map _id to id for the rest of the app, and never leak driver details.1 problem
- Handling Database Errors Which errors the driver throws (duplicate keys, validation, bad ids, an unreachable server) and how to turn each into the right HTTP status without leaking internals.1 problem
- Transactions Single-document writes are already atomic; for changes across documents use a session and withTransaction, pass the session to every operation, and keep transactions short.1 problem
- Paging Large Collections Why skip gets slow on deep pages, and range-based (keyset) paging: continue after the last item's sort key with a cursor token, backed by an index.1 problem
-
- Pro
Unit 8:An Express API on MongoDB
Routes over collections, operator injection, and the bookmarks API boss.
- An Express API on MongoDB Wire routes to collections: an app factory that takes the db, parse and validate route and query parameters before they reach a filter, project the response, and answer 404 and 400 correctly.1 problem
- Operator Injection NoSQL injection: a JSON body or query string that smuggles an operator like $ne into a filter. Check types at the boundary, build filters from known fields, and never pass request objects through.1 problem
- Boss: A Bookmarks API Put it all together: validation, a unique index and 409s, ObjectId ids, filtering and paging with totals, an aggregation endpoint and deletes, in one Express API on MongoDB.1 problem
-
Start MongoDB for free
Enroll for free and units 1 and 2 are yours. DevArcade Pro opens every unit of every course, including new ones as they launch, monthly or yearly.