MongoDB
一句话解释
MongoDB 是 NoSQL document 数据库那个存储数据 as flexible JSON-如 documents (BSON) in 集合.
用大白话说
MongoDB 是一种popular NoSQL document database。 Instead of tables and rows, it stores documents (JSON-like objects) in collections. Each document can have any fields — there is no fixed schema.
例如, a 用户 collection might contain:
{ "name": "Ada", "email": "ada@示例.com", "skills": ["math", "code"] }
{ "name": "Grace", "email": "grace@示例.com", "rank": "admin" }
Notice the two documents have different fields — MongoDB allows this. You query with a JSON-based query language (not SQL), though many tools provide SQL-like interfaces.
MongoDB is good for:
- Rapidly changing data shapes
- Horizontal scaling (sharding)
- Storing nested or hierarchical data
It trades some query power and consistency guarantees for flexibility and scale.
示例
javascript
// Insert a document
db.users.insertOne({
name: "Ada Lovelace",
email: "[email protected]",
skills: ["math", "programming"]
});
// Query documents
db.users.find({ skills: "math" });MongoDB 存储 flexible documents. 查询查找所有用户谁 有 'math' in 它们的 skills 数组.
相关术语
相关资源
相关课程
- MongoDB 基础
学习 MongoDB 基本.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。