MongoDB Introduction
MongoDB is a document database — instead of storing data in rows and tables like a relational database, it stores data as flexible, JSON-like documents grouped into collections. Each document can have its own shape, nested arrays and sub-documents live directly inside the parent record, and there's no need to define a rigid schema before you start writing data.
That flexibility made MongoDB the default choice for a generation of web applications, and it remains one of the most widely used databases for content-heavy, rapidly evolving, or highly variable data models.
Why Document Databases Exist
Relational databases model the world as normalized tables connected by foreign keys — great for consistency, but it means a single "user profile" or "product" often gets split across half a dozen joined tables. Document databases flip that: related data that's usually read together (a user and their addresses, a blog post and its comments) can live in one document, fetched in a single read with no joins.
This isn't a strictly "better" model — it's a different set of tradeoffs, covered in depth on the MongoDB vs SQL page later in this series.
A Quick Look at a Document
Relational (SQL) | Document (MongoDB) |
|---|---|
Row in a table | Document in a collection |
Table | Collection |
Foreign key + JOIN | Embedded sub-document or array |
Schema enforced by the database | Schema optional, enforced by the app (or JSON Schema validation) |
Primary key column | _id field (auto-generated ObjectId by default) |
What You'll Learn in This Series
The core concepts: documents, collections, BSON, and the _id field
Getting set up — installing MongoDB locally, using MongoDB Compass, or spinning up a free Atlas cluster
CRUD operations — inserting, querying, updating, and deleting documents
The full query operator language ($eq, $in, $regex, array operators, and more)
Indexing — how to make queries fast, and the patterns that make them slow
The aggregation framework — MongoDB’s pipeline-based approach to reporting and analytics
Data modeling — when to embed data versus reference it across collections
Production topics — transactions, replication, sharding, security, and performance tuning
Who This Is For
This series assumes you're comfortable with basic programming concepts and JSON, but it doesn't assume prior database experience. If you've used SQL before, you'll find frequent callouts comparing MongoDB concepts to their relational equivalents to help you map what you already know onto the document model.
mongosh (the MongoDB Shell) syntax, which is also the syntax used directly by most official drivers (Node.js, Python, Java, and others) with only minor language-specific differences.