Document Database Model
You'll learn what document-oriented databases are and how they fundamentally differ from relational tables.
What is a Document Database?
A document database stores data as documents—typically JSON, BSON, or XML structures—rather than rows in tables. Think of each document as a complete, self-contained record, like a digital filing cabinet where each folder contains all related information about one entity in a single place.
Unlike relational databases that spread information across multiple normalized tables, document databases embrace denormalization: related data lives together in nested structures.
Schema-Less Design
Document databases are often called "schema-less" or "schema-flexible." This means:
- No predefined structure required: You don't declare columns before inserting data
- Documents in the same collection can have different fields: One user document might have an
address, another might not - Easy evolution: Add new fields to new documents without altering existing ones
This flexibility is perfect for applications with evolving requirements or heterogeneous data.
Documents vs Relational Tables
Relational tables store data in rows with fixed columns:
- Data normalized across multiple related tables
- Joins required to reassemble complete entities
- Schema enforced at the database level
Documents store complete entities:
- Nested objects and arrays inside a single document
- No joins needed for related data
- Schema enforced at the application level (if at all)
For example, a user with multiple addresses in a relational DB requires two tables; in a document DB, addresses are simply an array within the user document.
Key Takeaway: Document databases store self-contained, flexible JSON-like documents instead of fixed-schema rows, enabling schema-less design and eliminating the need for joins to retrieve complete entities.