0Pricing
MongoDB Academy · 课时

NoSQL 类型:文档、键值、列式与图

您将比较 NoSQL 的四大类别,并将每一类对应到真实世界的使用场景。

NoSQL 类型:文档、键值、列式与图 是 CoddyKit 上的免费 MongoDB Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 MongoDB Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 MongoDB Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

The NoSQL Family Tree

"NoSQL" isn't one thing — it's a family of four: document, key-value, wide-column, and graph stores. MongoDB is a document store. Let's meet them all.

Document Stores: Rich Nested Data

Document stores keep data as flexible JSON-like documents, with nested objects and arrays all in one place. MongoDB leads here — the most versatile NoSQL type.

// Document store example - a product document
{
  _id: 'prod_001',
  name: 'Wireless Headphones',
  category: 'Electronics',
  specs: { battery: '30h', connectivity: 'Bluetooth 5.0' },
  reviews: [
    { user: 'alice', rating: 5, comment: 'Great!' }
  ],
  price: 79.99
}

Key-Value Stores: Blazing Fast Simplicity

Key-value stores like Redis are the simplest: every item is just a key and a value. Lookups are instant, perfect for caches, sessions, and leaderboards.

// Redis key-value example
SET session:user_42 '{"userId":42,"token":"abc123","expiresAt":1700000000}'
GET session:user_42
// Returns the JSON string immediately - O(1) lookup

// Redis also supports richer structures per key:
LPUSH leaderboard 'alice:9500'
LPUSH leaderboard 'bob:8700'
LRANGE leaderboard 0 9  // top 10

Wide-Column Stores: Analytical Scale

Wide-column stores like Cassandra spread data across many machines and swallow huge write loads. Ideal for IoT sensors, logs, and time-series data.

// Cassandra CQL - wide-column table design
CREATE TABLE sensor_readings (
  device_id  UUID,
  recorded_at TIMESTAMP,
  temperature FLOAT,
  humidity    FLOAT,
  PRIMARY KEY (device_id, recorded_at)
) WITH CLUSTERING ORDER BY (recorded_at DESC);
// Partition key = device_id; clustering key = recorded_at

Graph Databases: Relationships First

Graph databases like Neo4j store connections as first-class data, so they fly through relationships. Great for social networks, fraud rings, and recommendations.

// Neo4j Cypher query - find friends of friends
MATCH (me:Person {name: 'Alice'})
      -[:FRIENDS_WITH]->(friend)
      -[:FRIENDS_WITH]->(foaf)
WHERE NOT (me)-[:FRIENDS_WITH]->(foaf)
  AND foaf <> me
RETURN foaf.name AS suggestion
LIMIT 10;

Comparing the Four Families

Each family shines somewhere: documents for most apps, key-value for caching, wide-column for IoT, graph for relationships. Always ask: how will I query my data?

When to Use a Document Store

Reach for a document store like MongoDB when your data is nested, your schema keeps changing, and you want rich queries without painful JOINs.

Multi-Model Databases

Big systems often mix databases — a pattern called polyglot persistence. MongoDB for data, Redis for caching, each tool doing what it does best.

NewSQL: The Best of Both Worlds?

NewSQL databases like CockroachDB try to blend NoSQL's scaling with SQL's safety. The SQL vs NoSQL choice is less black-and-white than it used to be.

MongoDB in the NoSQL Landscape

MongoDB leads document stores thanks to its BSON format, rich queries, ACID transactions, and the Atlas cloud platform. Often your first and best NoSQL stop.

Choosing the Right NoSQL Family

Quick guide: single-key lookups go to Redis, relationships to Neo4j, time-series to Cassandra, rich nested data to MongoDB. Unsure? MongoDB is a safe start.

Quick Check

Test your understanding of MongoDB & NoSQL Databases concepts from this lesson.

Lesson Recap

You met the four NoSQL families, saw why MongoDB's documents fit most apps, and learned how polyglot persistence mixes tools. Next: the CAP theorem.

常见问题解答

「NoSQL 类型:文档、键值、列式与图」课时是免费的吗?

是的 — 「NoSQL 类型:文档、键值、列式与图」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 MongoDB Academy 课程的其余内容,请升级到 CoddyKit PRO。 MongoDB Academy 课程共包含 4 节课。

「NoSQL 类型:文档、键值、列式与图」这节课中我会学到什么?

您将比较 NoSQL 的四大类别,并将每一类对应到真实世界的使用场景。 你通过在浏览器中直接运行的动手代码来练习 MongoDB Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 MongoDB Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 MongoDB Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「NoSQL 类型:文档、键值、列式与图」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 MongoDB Academy 课中编写并运行代码吗?

能。每节 MongoDB Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 关系型数据库的瓶颈
  2. NoSQL 类型:文档、键值、列式与图
  3. 用通俗语言理解 CAP 定理
  4. MongoDB 的定位
← 返回 MongoDB Academy