Coursera 笔记

Module 02 · Introducing MongoDB: An Open-Source NoSQL Database

Reading: Best Practices of MongoDBMongoDB 的最佳实践

Coursera ↗

In this reading, you'll learn about the definition of MongoDB and describe the best practices for MongoDB.
在本阅读中,您将学习 MongoDB 的定义,并描述 MongoDB 的最佳实践。

What is MongoDB? 什么是 MongoDB?

MongoDB is an open source document-oriented database designed to store large data sets for industries. It enables efficient work with data and falls under not only structured query language (NoSQL) database because data storage and retrieval do not form tables.
MongoDB 是一个为行业设计用于存储大型数据集的面向文档的开源数据库。它能够高效地处理数据,不仅属于结构化查询语言(NoSQL)数据库,因为数据存储和检索不形成表格。

MongoDB. Inc., under a server-side public license (SSPL), manages and develops the MongoDB database. It provides driver support for various programming languages, such as C, C++, C #, .Net, Go, Java, Node.js, Perl, PHP, Python, Motor, Ruby, Scala, Swift, and Mongoid.
MongoDB 公司,在服务器端公共许可证(SSPL)下,管理和开发 MongoDB 数据库。它为多种编程语言提供驱动支持,如 C、C++、C #、.Net、Go、Java、Node.js、Perl、PHP、Python、Motor、Ruby、Scala、Swift 和 Mongoid。

Best practices: MongoDB 最佳实践:MongoDB

MongoDB offers flexibility and scalability to harness its full potential. Let's understand the best practices for optimizing performance and designing efficient schemas in MongoDB.
MongoDB 提供了灵活性和可扩展性,以充分发挥其全部潜力。让我们了解 MongoDB 中优化性能和设计高效模式的最佳实践。

Data Modelling 数据建模

MongoDB offers a flexible document-based model for representing complex, hierarchical data structures. Therefore, it is important to thoroughly understand the application's data requirements to design a MongoDB schema. However, various factors such as data relationships, read patterns, and scalability are also important.
MongoDB 提供了一种灵活的基于文档的模型来表示复杂、层次化的数据结构。因此,为了设计 MongoDB 模式,必须彻底理解应用程序的数据需求。然而,数据关系、读取模式、可扩展性等各种因素也同样重要。

Indexing 索引

Indexing the fields that are frequently queried or used for sorting helps to improve query execution times. However, ensuring that the queries support appropriate indexes and avoid creating extra indexes is vital. This helps to impact the right performance and save storage space. Also, keep in mind that indexing is a continuous process; however, queries need to be monitored and updated based on the business requirements.
对经常查询或用于排序的字段进行索引有助于提高查询执行时间。然而,确保查询支持适当的索引并避免创建额外索引至关重要。这有助于影响正确的性能并节省存储空间。此外,请记住索引是一个持续的过程;但是,根据业务需求,需要监控和更新查询。

Aggregation framework 聚合框架

The MongoDB aggregation framework provides powerful tools for performing data transformations, analytics, and computations within the database. Instead of fetching large datasets and processing them in application code, the aggregation pipeline can be used to perform complex operations directly within MongoDB. However, you should familiarize yourself with aggregation operators and stages, such as $match, $group, $project, and $lookup, to manipulate and aggregate data efficiently.
MongoDB 聚合框架提供了强大的工具,用于在数据库内执行数据转换、分析和计算。与其从数据库中获取大型数据集并在应用程序代码中处理它们,不如使用聚合管道直接在 MongoDB 内执行复杂操作。然而,您应该熟悉聚合操作符和阶段,如 $match、$group、$project 和 $lookup,以高效地操作和聚合数据。

Scaling horizontally 水平扩展

Scaling horizontally is one of the key points of MongoDB. Sharding helps distribute data across servers or shards to handle large volumes of data and high throughput workloads. However, consider the scalability requirements and plans for early sharding when designing MongoDB deployment. Further, select an appropriate shard key to distribute data equally across the shards by regularly monitoring their distribution and performance based on application growth.
水平扩展是 MongoDB 的关键点之一。分片有助于将数据分布在服务器或分片上,以处理大量数据和高吞吐量工作负载。然而,在设计 MongoDB 部署时,应考虑可扩展性需求并尽早进行分片规划。此外,根据应用程序的增长,选择合适的分片键来通过定期监控它们的分布和性能,以平等地分配数据到各个分片中。

Preventing unauthorized access 防止未经授权的访问

Databases often contain valuable and sensitive information, such as personal data, financial records, intellectual property, and proprietary business information. To achieve this, follow security best practices such as enabling authentication, using role-based access control (RBAC) to define user permissions, and configuring network encryption with transport layer security/secure sockets layer (TLS/SSL). Regularly update MongoDB to the latest version to patch security vulnerabilities and maintain a robust security posture.
数据库通常包含有价值且敏感的信息,如个人数据、财务记录、知识产权和专有商业信息。为此,应遵循安全最佳实践,例如启用身份验证、使用基于角色的访问控制(RBAC)定义用户权限,以及配置使用传输层安全/安全套接层(TLS/SSL)的网络加密。定期将 MongoDB 更新到最新版本,以修补安全漏洞并保持强大的安全态势。

Summary 摘要

In this reading, you've learned about what MongoDB is. MongoDB is an open source document-oriented database designed to store large data sets for industries. It supports various programming languages such as C, C++, C#, .Net, Go, Java, Node.js, Perl, PHP, Python, Motor, Ruby, Scala, Swift, and Mongoid.
通过本次阅读,您了解了 MongoDB 是什么。MongoDB 是一个开源的文档型数据库,设计用于存储行业的大型数据集。它支持多种编程语言,如 C、C++、C#、.Net、Go、Java、Node.js、Perl、PHP、Python、Motor、Ruby、Scala、Swift 和 Mongoid。

To use the full potential of MongoDB, one should follow several best practices, such as:
要充分发挥 MongoDB 的潜力,应遵循以下最佳实践:

  • Data Modelling  数据建模
  • Indexing  索引
  • Aggregation framework  聚合框架
  • Scaling horizontally  水平扩展
  • Preventing unauthorized access 防止未经授权的访问