Document-oriented databases
corebeginnerMongoDB stores data as documents — JSON-like records that can nest objects and arrays — instead of rows in a table. Each document lives in a collection, and documents in the same collection do not have to share one fixed set of fields.
Think of it as
A relational table is a spreadsheet: every row has the same columns, and a value that belongs together with another table lives in a second sheet, joined by a key. A MongoDB collection is a folder of self-contained forms: each form (document) can carry everything about one thing — including the parts that would need a second sheet in a spreadsheet — nested right inside it.
What we're doing: Show one document holding data that a relational schema would split across two tables.
- 1
- The whole value is one document — one self-contained record.
- 4
- author is an embedded document: a relational schema would put this in a separate authors table and join on a foreign key.
Why this works: A relational design normalizes author into its own table so the name is not repeated per book, then joins the two at query time. A document design instead asks whether a book is ever read without its author — if the two are always fetched together, nesting author removes the join and the query becomes a single document read.
Assuming a document collection needs one shared schema, like a table
Wrong
Better
What you see: Treating a flexible-schema database as if it were relational forfeits its main advantage without gaining any of a relational database’s enforced-schema guarantees.
Why: MongoDB does not require every document in a collection to share one fixed set of fields — that flexibility is deliberate, not a gap to work around by hand-enforcing a rigid shape.
- document — field-value pairs
- embedded object — nested inline
- array — a list, nested too
Document terms vs. their relational rough-equivalent
Together
Remember: A document is a JSON-like BSON record; a collection groups documents that do not have to share one fixed schema. Nesting replaces some joins.
See also: documents and collections · document vs relational

