Database Manual / Data Modeling

Designing Your Schema设计架构

The schema design process helps you prepare an effective schema for your application. Following the schema design process helps you identify what data your application needs and how to best organize your data to optimize performance.模式设计过程可帮助您为应用程序准备有效的模式。遵循模式设计过程可以帮助您确定应用程序需要哪些数据,以及如何最好地组织数据以优化性能。

Use Cases用例

Planning and designing your schema is best done early in your application development process. Starting your application with good data modeling practices helps prevent schema and performance issues as your application grows. 规划和设计模式最好在应用程序开发过程的早期完成。使用良好的数据建模实践启动应用程序有助于在应用程序增长时防止模式和性能问题。When you follow schema design practices early and appropriately, you can achieve better performance and make it easier to scale your application in the future.当你尽早并适当地遵循模式设计实践时,你可以获得更好的性能,并使未来更容易扩展你的应用程序。

You can design your schema iteratively and modify your schema as the needs of your application change. MongoDB provides ways to seamlessly modify your schema without downtime. However, it can still be difficult to modify large-scale schemas that are used in production.您可以迭代地设计模式,并随着应用程序需求的变化修改模式。MongoDB提供了无缝修改模式而无需停机的方法。然而,修改生产中使用的大规模模式仍然很困难。

When you design your schema, you may need to strike a balance between performance and simplicity. Sometimes, the most performant schema takes many iterations and a great deal of testing to achieve. 在设计模式时,您可能需要在性能和简单性之间取得平衡。有时,最高效的模式需要多次迭代和大量测试才能实现。Depending on your application and the importance of optimization, you may want to establish a simple schema to cover basic functionality, before spending time on optimizations.根据您的应用程序和优化的重要性,在花时间进行优化之前,您可能希望建立一个简单的模式来覆盖基本功能。

Tasks任务

The schema design process consists of the following steps:方案设计过程包括以下步骤:

1

Identify your workload确定你的工作量

Identify the operations that your application runs most frequently. See Identify Application Workload.确定应用程序最频繁运行的操作。请参阅识别应用程序工作负载

2

Map relationships映射关系

Identify the relationships in your application's data and decide whether to link or embed related data. See Map Schema Relationships.确定应用程序数据中的关系,并决定是链接还是嵌入相关数据。请参见映射模式关系

3

Apply design patterns应用设计模式

Apply schema design patterns to optimize reads and writes. See Apply Design Patterns.应用模式设计模式来优化读写操作。请参见应用设计模式

4

Create indexes创建索引

Create indexes to support common query patterns. See Create Indexes to Support Your Queries.创建索引以支持常见的查询模式。请参阅创建索引以支持查询