MongoDB
The dominant document database. Schemaless flexibility, JSON-shaped documents, harder consistency tradeoffs.
Mindmap
The plain-English version
MongoDB is a document database — it stores JSON-like documents (BSON, technically) instead of rows in tables. You can have wildly different shapes in the same collection. Schemaless by default; schema validation is opt-in. Released 2009. The reference "NoSQL" database.
The problem it solves
MongoDB shines when your data doesn't fit a rectangle — nested structures, optional fields, rapidly evolving shape. It struggles when your data does fit a rectangle and benefits from joins. Many teams that started with Mongo for flexibility migrated to Postgres + JSON columns once schemas stabilized.
Alternatives
| Alternative | Type | When it wins |
|---|---|---|
| Postgres | database | The serious open-source relational database. The default choice for most production apps that need structured data. |
| Redis | in-memory store | The in-memory key-value store. Fast cache, fast queue, fast everything that doesn't need durability. |
| Prisma | ORM | The TypeScript-first ORM. Schema-driven, type-safe, the default for most modern Node apps. |
Deep links
The words you'll hear
- Document / Collection
- A JSON-shaped record / a group of documents (analogous to row / table).
- Aggregation pipeline
- Mongo's query language. Stages of
$match,$group,$lookup. - Index
- Same idea as Postgres. Compound indexes are common.
- Sharding
- Splitting a collection across multiple servers. Mongo's strong scale-out story.
- Replica set
- Primary + replicas. Failover happens automatically.
- Atlas
- MongoDB's managed cloud service.
Bad vs. good prompt for MongoDB
Why it works: Asks for the design pattern decision (embed vs reference) explicitly — this is the central Mongo design question. Specifies the ODM (Mongoose) and language.
What bites real teams
$lookup is Mongo's join. It works but isn't as performant as a SQL join. Denormalize when you can.
"Just throw documents in!" — six months later, your collection has 47 fields, half deprecated. Use schema validation.
Mongo got multi-document transactions in 4.0, but they're more expensive than in Postgres. Design to need fewer.