Module 01 · Introducing NoSQL
Reading: NoSQL Database Types and Use CasesNoSQL 数据库类型和使用场景
After completing this reading, you will be able to describe the characteristics of several NoSQL database types, list their use cases, and identify frequently mentioned vendors associated with each NoSQL database type.
完成本阅读后,您将能够描述几种 NoSQL 数据库类型的特征,列出它们的使用场景,并识别与每种 NoSQL 数据库类型相关联的常用供应商。
As you review each use case, you'll see frequently used NoSQL database vendors mentioned in parentheses following the listed use case. This information is not an endorsement. This information is for market awareness.
在您审查每个使用场景时,您会在列出的使用场景后面看到括号中提到的常用 NoSQL 数据库供应商。这些信息并非推荐。这些信息是为了市场认知。
Gain the insights you need to be able to explain some of the technical considerations associated the use of MongoDB with a content management system (CMS).
获得必要的见解,以便能够解释使用 MongoDB 与内容管理系统(CMS)相关的一些技术考虑因素。
Document store databases 文档存储数据库
Document-store databases, also known as document-oriented databases, store data in a document format, typically JSON or BSON (binary JSON), where each document contains key-value pairs or key-document pairs. These databases are schema-less, allowing flexibility in data structures within a collection.
文档存储数据库,也称为面向文档的数据库,以文档格式存储数据,通常是 JSON 或 BSON(二进制 JSON),其中每个文档包含键值对或键-文档对。这些数据库是无模式的,允许在集合内对数据结构进行灵活配置。
Characteristics 特性
- Provides schema flexibility: Documents within collections can have varying structures, allowing for easy updates and accommodation of evolving data requirements.
提供模式灵活性:集合内的文档可以具有不同的结构,便于更新和适应不断变化的数据需求。 - Performs efficient create, read, update, and delete (CRUD) operations: well-suited for read and write-intensive applications due to their ability to retrieve whole documents.
执行高效的创建、读取、更新和删除(CRUD)操作:由于其能够检索整个文档,非常适合读写密集型应用。 - Provides scalability: horizontal scalability by sharding data across clusters.
提供可扩展性:通过将数据分片到集群中实现水平可扩展性。
Use cases 用例
- Content management systems (CMS): CMS platforms like WordPress use document store databases for fast storage and access to content types such as articles, images, and user data. (MongoDB)
内容管理系统(CMS):像 WordPress 这样的 CMS 平台使用文档存储数据库,用于快速存储和访问文章、图像和用户数据等内容类型。(MongoDB) - E-commerce: E-commerce platforms need effective management of product catalogs with diverse attributes and hierarchies, accommodating the dynamic nature of e-commerce product listings. (Couchbase or Amazon DocumentDB, using MongoDB compatibility)
电子商务:电子商务平台需要有效管理具有多样属性和层次结构的产品目录,以适应电子商务产品列表的动态特性。(Couchbase 或 Amazon DocumentDB,使用 MongoDB 兼容性)
Frequently mentioned vendors 经常被提及的供应商
- MongoDB
- Couchbase
- Amazon DocumentDB
Key-value stores 键值存储
Key-value stores are the simplest NoSQL databases, storing data as a collection of key-value pairs, where the key is unique and directly points to its associated value.
键值存储是最简单的 NoSQL 数据库,将数据存储为键值对集合,其中键是唯一的,并直接指向其关联的值。
Characteristics 特性
- Delivers high performance: efficient for read and write operations, optimized for speedy retrieval based on keys
提供高性能:读写操作高效,基于键值快速检索经过优化 - Provides scalability: easily scalable due to their simple structure and ability to distribute data across nodes
支持可扩展性:由于其结构简单且能够跨节点分布数据,易于扩展 - Uses caching for fast access
采用缓存机制以实现快速访问 - Provides session management
提供会话管理 - Works with distributed systems
与分布式系统协同工作
Use cases: 用例
- Enhanced web performance by caching frequently accessed data (Using Redis or Memcached)
通过缓存频繁访问的数据来提升网页性能(使用 Redis 或 Memcached) - E-commerce platforms, software applications, including gaming: Amazon DynamoDB provides a highly scalable key-value store, facilitating distributed systems' seamless operation by handling high traffic and scaling dynamically.
电子商务平台、软件应用程序,包括游戏:Amazon DynamoDB 提供了一个高度可扩展的键值存储,通过处理高流量和动态扩展,促进分布式系统的无缝运行。
Frequently mentioned vendors 经常提到的供应商
- Redis
- Memcached
- Amazon DynamoDB 亚马逊 DynamoDB
Column-family stores 列族存储
Definition: Column-family stores NoSQL databases, also referred to as columnar databases, organize data in columns rather than rows. These databases store columns of data together, making them efficient for handling large data sets with dynamic schemas.
定义:列族存储 NoSQL 数据库,也称为列式数据库,以列而不是行组织数据。这些数据库将数据列存储在一起,使其在处理具有动态架构的大数据集时效率很高。
Characteristics 特性
- Uses column-oriented storage: Data is grouped by columns rather than rows, allowing for efficient retrieval of specific columns.
采用列式存储:数据按列而非行进行分组,从而能够高效检索特定列。 - Delivers scalability: Distributed architecture for high availability and scalability.
提供可扩展性:分布式架构实现高可用性和可扩展性。
Use cases 用例
- IoT applications manage massive amounts of sensor data efficiently due to their ability to handle time-stamped data at scale, referred to as time-series data analysis. (Apache Cassandra)
物联网应用能够高效管理大量传感器数据,因为它们能够大规模处理时间戳数据,即时间序列数据分析。(Apache Cassandra) - Applications that store and analyze user preferences and behaviors usually deliver personalization. (HBase, part of the Hadoop ecosystem)
应用程序存储和分析用户偏好和行为通常提供个性化。(HBase,Hadoop 生态系统的一部分) - Large-scale data analysis.
大规模数据分析。
Frequently mentioned vendors 经常被提及的供应商
- Apache Cassandra
- HBase
Graph databases: 图数据库
Definition: Graph NoSQL databases are designed to manage highly interconnected data, representing relationships as first-class citizens alongside nodes and properties.
定义:图型 NoSQL 数据库旨在管理高度互联的数据,将关系作为与节点和属性同等重要的第一公民来表示。
Characteristics: 特点
- Analyzes the data using a graph data model: relationships are as important as the data itself, enabling efficient traversal and querying of complex relationships.
使用图数据模型分析数据:关系与数据本身同等重要,能够实现复杂关系的有效遍历和查询。 - Fast performance for relationship queries: optimized for queries involving relationships, making them ideal for social networks, recommendation systems, and network analysis.
关系查询的高性能:针对涉及关系的数据查询进行了优化,非常适合社交网络、推荐系统和网络分析。
Use cases: 应用场景
- Social networks require efficient data management of relationships between users, posts, comments, and likes. (Neo4j)
社交网络需要高效管理用户、帖子、评论和点赞之间的关系。(Neo4j) - Recommendation systems: Organizations need a database structure that can create sophisticated recommendation engines, analyzing complex relationships between users, products, and behaviors for precise recommendations. (Amazon Neptune)
推荐系统:组织需要一个数据库结构,能够创建复杂的推荐引擎,分析用户、产品和行为之间的复杂关系,以提供精确的推荐。(Amazon Neptune)
Frequently mentioned vendors 经常被提及的供应商
- Neo4j
- Amazon Neptune
- ArangoDB
Wide-column stores: 宽列式商店
Wide-column store NoSQL databases organize data in tables, rows, and columns, like relational databases, but with a flexible schema.
宽列式 NoSQL 数据库将数据组织成表、行和列,类似于关系数据库,但具有灵活的架构。
Characteristics: 特点
- Use columnar storage: Data is stored in columns, allowing for efficient retrieval of specific columns rather than entire rows.
使用列式存储:数据以列的形式存储,允许高效检索特定列而不是整行。 - Provide horizontal scalability and fault tolerance.
提供水平可扩展性和容错能力。
Use cases: 用例
- Analyzing big data: Efficiently handling large-scale data processing for real-time big data analytics. (Apache HBase used in conjunction with Hadoop)
分析大数据:高效处理大规模数据处理,用于实时大数据分析。(与 Hadoop 一起使用 Apache HBase) - Managing enterprise content: Large organizations databases need to manage vast amounts of structured data like employee records or inventory due. (Cassandra)
管理企业内容:大型组织数据库需要管理大量结构化数据,如员工记录或库存数据。(Cassandra)
Frequently mentioned vendors 经常提到的供应商
- Apache HBase
- Apache Cassandra
Expanded use case example: Using MongoDB for a content management system (CMS) 扩展用例示例:使用 MongoDB 构建内容管理系统(CMS)
Content management systems (CMS) intelligently collect, govern, manage, and enrich enterprise content, including HTML pages, images, articles, and more. Content management systems help companies deploy their content efficiently and securely across any cloud and within any application.
内容管理系统(CMS)能够智能地收集、管理、维护和丰富企业内容,包括 HTML 页面、图像、文章等。内容管理系统帮助企业高效且安全地在任何云环境和任何应用程序中部署其内容。
Good content management means that team members can quickly add, update, and remove content from the database and the associated pages that feature that content. Examples include pushing out breaking news, updating current news, including weather forecasts, pushing advertising content, updating college admission policies, launching new city services, and more.
良好的内容管理意味着团队成员可以快速从数据库和相关页面(这些页面包含该内容)中添加、更新和删除内容。例如,推送突发新闻、更新当前新闻、包含天气预报、推送广告内容、更新大学录取政策、推出新的城市服务等。
For example, using MongoDB as a backend database for a content management system (CMS) is a practical choice when you need to manage and serve a variety of content types, especially in scenarios where you expect frequent schema changes or scaling requirements.
例如,当您需要管理和提供多种类型的内容,尤其是在预期频繁的架构变更或扩展需求的情况下,使用 MongoDB 作为内容管理系统(CMS)的后端数据库是一个实用的选择。
Next, let's check out some of the aspects of managing content using a content management system, specifically using MongoDB.
接下来,让我们了解一下使用内容管理系统(特别是使用 MongoDB)管理内容的一些方面。
Content structure using MongoDB 使用 MongoDB 的内容结构
In MongoDB, you represent content as documents. Each document corresponds to a piece of content, such as an article, image, video, or page. You can use the subdocuments in the document to organize the content hierarchy and structure.
在 MongoDB 中,您将内容表示为文档。每个文档对应于一个内容项,例如文章、图像、视频或页面。您可以使用文档中的子文档来组织内容的层次结构和结构。
Example of structuring: Storing a blog post 结构示例:存储博客文章
When storing a blog post, you will store core attributes like title, content, created at, and the image URL. Then, using an array field, you can store tags. The comments on that post are stored as an array of objects.
在存储博客文章时,您将存储标题、内容、创建时间和图片 URL 等核心属性。然后,您可以使用数组字段存储标签。该文章的评论则存储为一个对象数组。
// Collection: posts
{
"_id":1,
"title":"Sample Blog Post",
"content":"This is the content of the blog post...",
"author":{
"name":"John Doe",
"email":"john@example.com",
"bio":"A passionate blogger.",
"created_at":"2023-09-20T00:00:00Z"
},
"created_at":"2023-09-20T08:00:00Z",
"tags":["mongodb","blogging","example"],
"comments":[
{
"text":"Great post!",
"author":"Emily Johnson",
"created_at":"2023-09-20T10:00:00Z"
},
{
"text":"Thanks for sharing!",
"author":"James Martin",
"created_at":"2023-09-20T11:00:00Z"
}
]
}
Metadata and indexing using MongoDB MongoDB 的元数据和索引
You can use the indexing capabilities of MongoDB to optimize content retrieval. You can create indexes on fields commonly used for filtering or searching, such as keywords, publication date, or content type, or use MongoDB's text index support for text search queries on fields containing string content. Text indexes improve performance when searching for specific words or phrases within string content.
您可以使用 MongoDB 的索引功能来优化内容检索。您可以在常用的过滤或搜索字段上创建索引,例如关键词、发布日期或内容类型,或者使用 MongoDB 的文本索引支持对包含字符串内容的字段进行文本搜索查询。文本索引在搜索字符串内容中的特定单词或短语时可以提高性能。
For example, you want to provide searching capability on the content of your blogs. You will first create a text index:
例如,您希望在您的博客内容上提供搜索功能。您将首先创建一个文本索引:
db.articles.createIndex( { subject: "text" } )
And then you can provide a query such as:
然后您可以提供一个查询,例如:
db.posts.find( { $text: { $search: "digital life" } } )
where MongoDB will look for stemmed versions of these words: digital or life
MongoDB 将查找这些词的词干版本:digital 或 life
Scaling your CMS using MongoDB 使用 MongoDB 扩展您的 CMS
As your CMS grows, MongoDB can help you scale. You can use sharding for horizontal scaling or use zone-based sharding for global distribution.
随着您的 CMS 的增长,MongoDB 可以帮助您进行扩展。您可以使用分片进行水平扩展,或使用基于区域的分片进行全球分布。
Using sharding for horizontal scaling (increased capacity) 使用分片进行水平扩展(增加容量)
Let's consider a company that currently has 100 million customers. This company expects to expand its customer base to 200 million customers. This increase in the number of customers means that the company will need to double its IT data storage hardware. The company can scale vertically, which can cost exponentially more as the hardware cost isn't linear with the performance. The following diagram shows that the company can scale horizontally and use sharding to manage the databases.
让我们考虑一家目前拥有 1 亿用户的公司。该公司预计将其用户群扩展到 2 亿用户。用户数量的增加意味着该公司需要将其 IT 数据存储硬件翻倍。该公司可以选择垂直扩展,但这可能成本呈指数级增长,因为硬件成本与性能并非线性关系。下图显示了该公司可以通过水平扩展并使用分片来管理数据库。

However, the use of sharding for horizontal scaling provides the company with double the throughput at double the cost.
然而,使用分片进行水平扩展使该公司在成本翻倍的情况下,吞吐量也翻倍。
Recap 总结
Understanding the nuanced characteristics of each NoSQL database type is crucial in selecting the right database solution that aligns with specific application requirements, scalability needs, and performance expectations.
理解每种 NoSQL 数据库类型的细微特征,对于选择与特定应用需求、可扩展性需求和性能预期相一致的合适数据库解决方案至关重要。