Skip to content

Intro & Documents

Welcome to MongoDB — From Zero to Hero. This course takes you from never having touched a database to comfortably modelling data, querying it, indexing it for speed, aggregating it into reports, and running it in production. We will work in concrete examples the whole way: a small, made-up world of library members and the books they borrow, kept deliberately tiny so the ideas stay in the spotlight. Every operation is shown five ways — in the mongosh shell and in the Node.js, Python, Go, and Rust drivers — so the lessons transfer to whatever stack you actually work in.

MongoDB is a document database: instead of storing your data as rows in rigid tables, it stores documents — JSON-like objects with fields, nested objects, and arrays — grouped into collections. A document is allowed to look however your data naturally looks, so the shape of the data in the database tends to match the shape of the objects in your code, with no translation layer in between.

The course is eight modules. Each one builds on the last, so working through them in order is the smoothest path, though every module also stands on its own if you want to jump to a specific topic.

flowchart TD
  M1["1. Intro & Documents"] --> M2["2. CRUD"]
  M2 --> M3["3. Querying"]
  M3 --> M4["4. Indexes"]
  M4 --> M5["5. Aggregation"]
  M5 --> M6["6. Data Modeling"]
  M6 --> M7["7. Transactions & Consistency"]
  M7 --> M8["8. Operations & Scaling"]
The eight modules of the course, in the order they build on each other
  • Intro & Documents — the module you are in now. What a document database is, how to run MongoDB locally with Docker, the shell and Compass, and what a BSON document really is.
  • CRUD — the four everyday verbs: creating, reading, updating, and deleting documents.
  • Querying — filtering with operators, sorting, limiting, projecting fields, and paging through results.
  • Indexes — making queries fast, understanding what an index costs, and reading a query plan.
  • Aggregation — the pipeline that groups, reshapes, and summarises data into reports.
  • Data Modeling — deciding when to embed related data and when to keep it in separate collections.
  • Transactions & Consistency — multi-document atomicity, read and write concerns, and the guarantees you can rely on.
  • Operations & Scaling — backups, replica sets for resilience, and sharding for growth.

This first module gives you everything you need before the real work begins:

  1. What is MongoDB — document database versus relational, and when each one fits.
  2. Setup with Docker — running MongoDB locally from the official image in a couple of commands.
  3. The shell and Compass — talking to the database from the terminal and the GUI, and connecting from each driver.
  4. Documents and BSON — the binary format under your JSON, and the types a document can hold.
  5. Document vs relational — a side-by-side translation of relational vocabulary into MongoDB terms.

Every output in this course was captured, not typed: mongo 8.3.11 (what mongo:8 resolves to on 2026-09-30), mongosh 2.11.1, Node.js driver 7.7.0, run on one Mac against a container. Python, Go and Rust tabs mirror the verified shell/Node behaviour and, where a lesson says so, were run once in scratch programs (PyMongo 4.18.2, Go driver v2.9.1, Rust driver 3.9.1); they are not executed by the course’s automated checker, which covers the mongosh and Node fences. Modules 1 to 6 work on any MongoDB; module 7 (transactions, change streams) needs a replica set, which the Setup lesson shows how to start.

Every lesson seeds its own data, so you can open any lesson on its own. The shape stays the same across modules - this is the dataset the lessons build (a runnable check that it loads):

mongosh/intro-dataset.js
db.members.insertMany([
{ name: "Ada", joined: 2023, fines: 0, city: "Cambridge", borrowed: ["Compilers"] },
{ name: "Grace", joined: 2024, fines: 0, city: "Arlington", borrowed: ["Compilers", "Algorithms"] },
{ name: "Linus", joined: 2023, fines: 2, city: "Helsinki", borrowed: [] },
]);
db.sales.insertOne({ title: "Compilers", genre: "cs", quantity: 2, price: 45.5, buyer: "Ada" });
console.log(db.members.countDocuments(), db.sales.countDocuments());
assert.strictEqual(db.members.countDocuments({ fines: { $gt: 0 } }), 1);
3 1
  • You do not need to memorise anything here. The goal of this module is fluency with the vocabulary — document, collection, BSON, _id — so the later modules read smoothly.
  • Everything runs locally. We use Docker so there is nothing to install permanently and nothing to clean up by hand later.
  • If you already know SQL, the final lesson of this module is the fastest way to map what you know onto MongoDB.

This course shows the Node.js driver next to the shell, and the most common Node mistake in AI-written code is a forgotten await:

🐛 Spot the bug

// AI comment: "insert the member, then confirm the count"
const members = db.collection("members");
members.insertOne({ name: "Grace" });
const n = await members.countDocuments();
console.log(n === 1 ? "saved" : "missing");
Show the answer

insertOne returns a promise; without await the code races ahead. We ran the pattern 20 times (deleting the collection first each time): the count was 0 in 15 of the 20 runs, so the check printed “missing” for a write that succeeds a moment later. A rejection of the un-awaited promise is also lost - a duplicate-key insert failed silently until we attached a .catch. The fix is one word:

app/intro-await.mjs
const members = db.collection("members");
await members.deleteMany({});
await members.insertOne({ name: "Grace" });
const n = await members.countDocuments();
console.log(n === 1 ? "saved" : "missing");
if (n !== 1) throw new Error("expected 1");
saved

The course is one loop: model a document, write it (CRUD), read it (querying), make the read fast (indexes), summarise it (aggregation), keep it correct (transactions) and alive (operations). Modules 1 to 3 are the vocabulary of that loop; the rest are the properties you add once the loop works.

ChoiceBenefitCost
The document model’s flexible schemaStart writing code and shipping features fast, without fully designing a schema on day oneNo compile-time guarantee that every document in a collection shares the same shape - consistency becomes your team’s own responsibility
BSON with more types than JSONStore Date, ObjectId, and Decimal128 exactly, without converting values yourselfEach language driver maps these types onto its own native types differently (the Documents and BSON lesson measured it)
Standalone container for learningSimplest to run, supports a root userNo transactions or change streams; module 7 needs the replica-set variant
  • “No schema means no design.” - a flexible schema still needs discipline; the What is MongoDB lesson shows a typo field accepted silently.
  • “Each module is fully independent.” - later modules lean on the vocabulary here (document, field, BSON, _id).
  • “MongoDB fits every job.” - the module covers when a relational database is still the better tool.
  • “The Docker container from Setup covers the whole course.” - a standalone one does not: module 7 needs a replica set.
  • “Missing await still works if the write is quick.” - 15 of 20 counts were 0 in the run above.

Real-world example

eBay - uses MongoDB as one of its core enterprise data platform standards, powering customer-facing applications on ebay.com, including a product catalog scaled across large replica sets for massive read volume (mongodb.com/customers/ebay, 2017).

Forbes - uses MongoDB Atlas as the backend for the CMS that serves all content on Forbes.com; the flexible data structures let the team add components quickly and cut average build times from 25 to 9 minutes (mongodb.com/customers/forbes, 2019).

What is the basic unit of data MongoDB stores?
How many modules make up this course?
Which module teaches making queries fast?
Which module needs a replica set rather than a plain standalone container?
In Node, members.insertOne(doc) is called without await, and countDocuments() runs right after. What did the real run show?