Document Store: Keeping Each Record Whole in One Flexible Document
A document store saves each record as one flexible, JSON-like document, so a whole item can be read in one step. Here is how it works and where it falls short.
In short
A document store saves each record as one flexible, JSON-like document, so a whole item such as a product can be read in one step.
10 min readFree
What You Will Learn
Think about a web page for one product in an online shop. The page needs the name, the price, the photos, and the customer reviews. A document store is a kind of database that keeps all of those facts together in one record. The page can then get everything it needs in one request.
This lesson explains what a document store holds, why teams choose one, and what it costs them. It walks through one product page step by step and ends with two short quizzes. You do not need database experience. Other lessons cover the other database types, so this one stays with documents.
Key words
- Database
- A program that stores data safely and answers questions about it.
- Document store
- A database that saves each record as a self-contained document, and finds records by key or by the fields inside them.
- NoSQL
- A family of databases that do not mainly use fixed tables with rows and columns.
- JSON
- A plain text way to write data as named values, such as name and price. Curly braces hold the fields.
- Document
- One stored record. It is a set of field and value pairs, shaped like JSON.
- Field
- One named piece of information inside a document, such as price.
- Collection
- A named group of documents, like a folder that holds related records.
- Key or ID
- A unique label that finds exactly one document.
- Schema
- The agreed shape of data: which fields exist and what kind of value each holds.
- Join
- A step that combines records from two places at read time, so one query returns both.
- Embedding
- Putting related data inside the same document, as a nested part of it.
- Referencing
- Storing only the ID of another document, then fetching that document separately.
- Transaction
- A group of changes that either all succeed or all fail together.
- Atomic
- A change that happens as one whole step. Other readers see it fully done or not done at all.
- Horizontal scaling
- Handling more work by adding more machines, instead of making one machine bigger.
What Is a Document?
A document is one record in a document store. It holds field and value pairs, where each piece of information has a name and a value. The layout looks much like JSON. Some systems store a compact binary version of this shape inside, but you can still reason about it as fields and values.
Documents are often described as self-contained. That means one document holds everything a single item needs, so the database does not have to search other tables to build it.
What Are Fields, Nested Data, and Arrays?
A document can hold more than plain text and numbers. Its values can be built from three kinds of parts. Each part makes it easier to store one real-world item in one place.
Simple fields
A field can hold a text value, a number, or a true or false value. A product name and a price are common examples.
Nested fields
A field can hold another document inside it. A shipping address can sit under one heading, with its own street and city fields.
Arrays
A field can hold a list of values. A product can keep a list of image file names, or a list of customer reviews, in one field.
What Are Collections and Unique IDs?
Documents are grouped into collections. A collection keeps related records together, such as all products in one place. Each document also gets a unique ID. The ID is the fastest way to fetch one exact record. In MongoDB, the ID field is called _id, and the system creates one for you if you leave it out.
Documents in one collection do not have to share the same fields. One product may have a field for battery life, while a shirt has none. The database does not force every record into one fixed layout. Your app still needs a clear plan for which fields each record should have.
Tip
Think of a collection as a set of folders, and a document as one page in a folder. Each page can have different notes on it, but each page still has its own unique label.
Why Do Teams Choose a Document Store?
Teams pick a document store for three main reasons. Each reason matches a common pattern in modern apps, where data changes often and is read as a whole unit.
Flexible shape
New kinds of items can add new fields without a rebuild of every table. A team can launch a new product type and store its extra facts right away.
One read instead of many
Related data can sit together in one document, so one read fetches everything. The database does not need joins to stitch separate tables together. That can make page loads simpler and faster.
Scaling out across machines
Many document stores are built to split data across several machines. As the load grows, you add machines instead of buying one bigger server.
The best fit is data that your app reads and writes as one unit. A user profile is a good example, and so is a product page. The whole record is shown together, so storing it together saves work.
What Are the Trade-offs?
No database is free of cost. A document store makes some tasks easier and some tasks harder. Knowing the costs helps you decide when it is the wrong tool.
Duplicated data
The same fact can end up in many documents. When a shop name changes, every copy may need an update. Updating duplicated data across many documents can be hard to keep correct.
Hard many-to-many links
A many-to-many link means many items relate to many others, like students and courses. Storing these links is harder.
Weaker transactions across documents
A change to one document is safe as one step. A change that must span several documents needs a multi-document transaction, and some systems support these less well or at a higher cost.
These costs mean a document store fits some access patterns better than others. If your app mostly asks a few deep questions across many linked tables, a relational database may serve you better.
The next part looks at a common design choice that affects these costs: where related data should live.
Embedding Versus Referencing
When two kinds of data relate, you can embed one inside the other or reference it by ID. Embedding keeps everything in one read, but it can repeat data and grow large. Referencing keeps one official copy, but it needs an extra read to bring the related data back.
A common rule is to embed data that is always read with its parent and stays small. Use references when the related data is shared by many parents, is large, grows without a limit, or is read on its own. A DbSchema article describes the same idea: embed what you read together, and reference what is shared or changes separately.
Tip
Ask one question first: does the page always show the child data with the parent? If yes, embedding is a good first guess. If the child grows forever, switch to references.
Worked Example: A Product Page
Here is one real use of the idea. An online store keeps each product as one document in MongoDB. The document holds the name, the price, a list of images, and an array of customer reviews. Follow the steps to see why the page loads with one read.
- 1
Picture what the page shows
The product page needs the name, the price, the photos, and the reviews. All four belong to one product, so they belong together.
- 2
Write the product as one document
Store the product as one document. The name and price are simple fields. The images are an array. The reviews are an array of small nested documents.
- 3
Load the page with one read
When a shopper opens a product, the app asks for that product's ID. The database returns the whole document, so no second lookup is needed for the reviews.
- 4
Add a laptop with a specs field
A laptop needs fields that a shirt does not, such as a specs field for processor and memory. The team adds it to the new laptop document. No table has to change, and other products keep their own shape.
- 5
Watch the size of the reviews list
The reviews array grows each time someone writes one. A MongoDB document may not exceed 16 MiB, so a very popular product could eventually need a different design, such as references to a separate reviews collection.
The shape of the record looks like this. The values are examples, not real data.
{
"_id": "product-1001",
"name": "Trail Shoe",
"price": 89.5,
"images": ["front.jpg", "side.jpg"],
"reviews": [
{"author": "Reviewer A", "stars": 5},
{"author": "Reviewer B", "stars": 4}
]
}A Python dictionary works much like a document, so the sample below lets you run the same idea. It reads the name, counts the reviews, and computes the average star rating. All of this comes from one object, with no second lookup.
product = {
'name': 'Trail Shoe',
'price': 89.5,
'images': ['front.jpg', 'side.jpg'],
'reviews': [
{'author': 'Reviewer A', 'stars': 5},
{'author': 'Reviewer B', 'stars': 4},
],
}
print(product['name'])
print(len(product['reviews']))
average = sum(r['stars'] for r in product['reviews']) / len(product['reviews'])
print(average)
Output
Trail Shoe 2 4.5
Check Your Thinking
Try these two short scenarios. Each one needs the ideas from this lesson to answer well. Pick the option you think is best, then read the reason.
Blog Post Scenario
A team builds a blog. Each post has a title, a body, a list of tags, and a list of comments. The number of comments varies from post to post. The page always shows the whole post at once.
Quick check
Would a document store fit this blog, and why would storing the comments inside the post help?
Students and Courses Scenario
A school app stores students and courses. Each student takes many courses, and each course has many students. The team asks whether to embed a full copy of every course inside each student's document.
Quick check
What is the best design for this many-to-many link in a document store?
Key Takeaways
A document store saves each record as a self-contained, JSON-like document. Documents sit in collections, and each one has a unique ID. Fields can be simple, nested, or arrays, and documents in one collection do not have to share a fixed layout.
Teams choose this model when data is read and written as a whole unit. Related data can sit together, so one read fetches it. The costs are duplicated data, weaker links between many records, and weaker transactions across several documents. Before you choose, ask how your app reads the data.
Tip
Start by sketching the screen your user sees. If all of its data comes from one item, a document may fit. If it pulls from many items that change on their own, a document store may cause trouble.
Sources
- MongoDB Manual: What is MongoDB? An Overview of the Database
- MongoDB Docs: Best Practices for Data Modeling (embedding vs. references)
- MongoDB Docs: Embedded Relationships and Manual References (EF Core Provider)
- MongoDB: Document Database, NoSQL basics
- dbschema: Introduction to MongoDB Tutorial (2025)
- dbschema: MongoDB Relationships: Embed vs Reference
- AlgoMaster: Document Databases (system design)
- Aerospike: Features, Benefits, and Challenges of Document Databases
- Appwrite: What is a document database? An expert guide for developers
- Wikipedia: Document-oriented database
- documentdatabase.org: Switching from relational to document models, Part 2
- Learnomate: MongoDB Data Modeling Best Practices: Embed vs Reference
Last updated on 17 November 2026
Related lessons
Learn with me
Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.