Lesson 9 of 9 · 23m
When MongoDB Is the Wrong Choice
Recognize relational invariants, ad hoc joins, strict reporting, and operational complexity cases where PostgreSQL or another tool is simply better.
The most expensive MongoDB lesson is learning that not every problem is a document problem. I like MongoDB when it is used for what it is good at: flexible but governed documents, high-volume operational reads, clear ownership boundaries, and models shaped around access patterns. I become very boring very quickly when someone proposes using it as a relational database with looser constraints and more JSON.
Strong relational invariants are a warning sign
If the core of your domain is a web of entities with strict referential integrity, many-to-many relationships, and invariants spanning rows, relational databases are often the honest tool:
ledger entries tied to accounts
inventory tied to warehouses, suppliers, allocations, and returns
students tied to courses, sections, prerequisites, instructors, and enrollmentsYou can implement these in MongoDB. People do. Then they slowly rebuild foreign keys, cascade rules, joins, and constraint checking in application code. PostgreSQL already solved this with decades of production scar tissue.
Ad hoc joins and changing questions matter
Document modeling optimizes for known access paths. That is a strength in product workloads and a weakness in exploratory ones. If analysts constantly ask new cross-entity questions, a document model optimized for application screens becomes hostile. $lookup pipelines can answer some questions, but they are not a substitute for a relational planner in a general reporting workload.
Transactions do not make MongoDB relational
Yes, MongoDB has multi-document transactions. No, that does not mean you should model a highly relational system across many collections. Transaction cost, lock contention, operational complexity, and schema drift accumulate. A database choice should reduce the need for heroics, not create permanent demand for them.
Choose MongoDB when the shape fits
Good fits often look like this:
catalogs and product content with evolving attributes
event-like documents with clear tenancy and bounded retention
user profiles and preferences read as a unit
workflow state where one aggregate owns most mutations
operational data served by known, stable access pathsPoor fits often look like this:
financial ledgers requiring strict relational constraints
highly normalized enterprise data with constant ad hoc joins
reporting systems where the questions change faster than the model
tiny teams that do not want to operate replication and backup disciplineOperational competence is part of the database choice
MongoDB requires real operational care: indexes, replica set monitoring, backup testing, upgrade planning, driver behavior, connection lifecycle, oplog sizing, and query review. If the organization cannot staff that discipline, a managed relational service with boring defaults may be safer. "It is managed" reduces toil; it does not remove the need to understand failure modes.
Polyglot persistence is normal
The answer is often not MongoDB versus PostgreSQL. It is PostgreSQL for transactional relational truth, MongoDB for document-shaped operational data, a search engine for text relevance, and object storage for large binaries. Be explicit about the system of record for each fact. Two databases storing the same truth without a reconciliation story is not architecture; it is future incident homework.
Field notes
- If the data model diagram looks like a spiderweb of relationships, listen to it.
- Flexible schema is a benefit for evolution, not a license to skip domain modeling.
- Do not choose a database because a tutorial used it or because a vendor demo looked fast.
- The correct question is not "Can MongoDB do this?" It is "What complexity are we accepting for the next five years?
Was this lesson helpful?