Document
In one line
A document is a NoSQL record — a flexible JSON-like object with any fields, stored in a collection.
In simple words
In a document database like MongoDB, a document is the unit of data storage — analogous to a row in a relational table. A document is a JSON-like object with fields and values, and unlike a relational row, it can have any structure.
For example:
{
"_id": "507f1f77bcf86cd799439011",
"name": "Ada Lovelace",
"email": "[email protected]",
"address": { "city": "London", "country": "UK" },
"skills": ["math", "programming"]
}
This single document contains nested objects and arrays — something that would require multiple tables and joins in a relational database. Documents are grouped into collections (analogous to tables).
Example
// A MongoDB document with nested data
const product = {
name: "Laptop",
price: 999,
specs: { cpu: "M2", ram: 16 },
tags: ["electronics", "portable"]
};
db.products.insertOne(product);A single document can contain nested objects and arrays — no need for separate tables.
Related terms
Related Resources
Related Lessons
- MongoDB Basics
Learn about documents and collections.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.