What Is a Document Database? Choose Document Boundaries Around Data Use
A document database stores each record as a document: a set of named values that can contain nested documents and arrays. You can put information that is usually read or changed together—such as an order and its shipping address—in one document, or connect independently managed entities with references. The key design question is not simply whether the database accepts JSON; it is which information should be read and changed together.
What does document data look like?
A document usually has object-like fields. An order might contain an ID, status, creation time, a nested shipping address, and an array of items. Document products support hierarchical structures similar to JSON, but their storage formats, data types, and query languages differ. MongoDB stores BSON documents, which include types such as dates and identifiers that are not represented the same way in JSON text.
{
"_id": "order-1042",
"customerId": "customer-17",
"status": "paid",
"shippingAddress": { "city": "Seoul", "postalCode": "04524" },
"items": [ { "sku": "mug-1", "quantity": 2, "unitPrice": 12000 } ]
}This is an illustrative structure, not data inserted into or run against a product. Nesting can keep information needed for one record together, but a document database does not mean there is no schema or validation. Products such as MongoDB provide schema validation, and applications still need rules for required fields, accepted values, and compatibility between versions.
Should related data be embedded or referenced?
An address that is read with an order and can vary by order is convenient to embed: one read can return both. In products with atomic single-document writes, related fields can also be changed together. By contrast, copying a shared customer profile into every order means every copy must be updated when the customer's address changes; missed updates can make the copies disagree. Keeping the customer in a separate document and referring to it by ID reduces duplication, but may require another read or a join-like operation.
| Design question | Embed in one document | Reference another document |
|---|---|---|
| How often are values read together? | Useful when almost always read together | Useful when often read separately |
| Do their lifecycle and changes match? | Fits child values created or changed with the parent | Fits independently changing or shared values |
| Is duplicated data a concern? | More copies mean update work and inconsistency risk | Less duplication, but related reads may take extra operations |
| Are size and count bounded? | Fits small, bounded child lists | Often better for growing lists or when only subsets are read |
For example, an order screen may need its items together, and the order may need to preserve the product name and price at purchase time. Those historical values can be a snapshot inside the order. Current inventory, however, should not be copied into every order if it must be updated consistently. A mixed design can keep the historical snapshot in the order and manage live inventory separately. This is an illustrative scenario; the right choice depends on access patterns and consistency requirements.
When does the model fit, and what should you watch?
Document models can help when an application reads and writes nested data as a unit or when records have optional fields that vary. If the document boundary matches the write unit, related values may be fetched in one query or changed in one document write. Larger documents are not automatically faster: if queries need only one nested item or an array keeps growing, extra data transfer and memory use can outweigh the benefit.
Deeply nested fields and independently searched values need deliberate query and index design. Indexes can speed reads, but consume storage and add work to writes. If the same fact appears in several documents, define how every copy will be updated. If changes across multiple documents must be atomic, check the product's transaction support and cost, and reconsider whether the data boundaries should be different.
A document database is not always an alternative to a relational database. PostgreSQL, for example, provides JSON types alongside relational tables. A mixed design can use columns and constraints for stable core fields and JSON for supplementary attributes that change shape. In either model, begin with the queries you actually run, the data that changes together, and where integrity rules must be enforced. Then check query and index plans against representative data.
Sources and scope
[MongoDB Manual: Documents and nested fields](https://www.mongodb.com/docs/manual/core/document/)
[MongoDB Manual: Embedded data](https://www.mongodb.com/docs/manual/data-modeling/embedding/)
[MongoDB Manual: References](https://www.mongodb.com/docs/manual/data-modeling/referencing/)
[PostgreSQL 19: JSON types](https://www.postgresql.org/docs/current/datatype-json.html)
MongoDB Manual 9.0 and PostgreSQL 19 documentation checked on 2026-11-22 provide the product-specific examples. A document model is not one fixed implementation or standard, so confirm features, limits, and query behavior in the documentation for your product. The JSON and order examples are illustrative and were not executed.