Document
一句话解释
document 是 NoSQL 记录 — flexible JSON-如对象使用任何字段, 存储 in 集合.
用大白话说
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": "ada@示例.com",
"地址": { "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).
示例
javascript
// A MongoDB document with nested data
const product = {
name: "Laptop",
price: 999,
specs: { cpu: "M2", ram: 16 },
tags: ["electronics", "portable"]
};
db.products.insertOne(product);单个 document 能包含 nested 对象 and 数组 — 否需要 for separate 表.
相关术语
相关资源
相关课程
- MongoDB 基础
学习关于 documents and 集合.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。