Database Manual / Data Modeling

Schema Design Anti-Patterns模式设计反模式

Schema design anti-patterns are inefficient ways to structure your database schema. They can create unnecessary complexity and cause performance issues. Recognizing and avoiding schema design anti-patterns can help create applications with better performance.模式设计反模式是构建数据库模式的低效方法。它们会造成不必要的复杂性并导致性能问题。识别和避免模式设计反模式可以帮助创建具有更好性能的应用程序。

Get Started开始使用

To learn more about schema design anti-patterns, see the following pages:要了解有关模式设计反模式的更多信息,请参阅以下页面:

Schema Design Anti-Pattern模式设计反模式Definition定义
Avoid Unbounded Arrays避免无边界数组A document stores an unbounded array that can grow to be too large. The large array can exceed the document size limit and cause a decrease in index performance.文档存储的无界数组可能会变得太大。大数组可能会超过文档大小限制,导致索引性能下降。
Reduce Number of Collections减少收款数量You create a large number of collections in your database. Having too many collections can decrease storage engine performance.您在数据库中创建了大量集合。集合过多会降低存储引擎的性能。
Remove Unnecessary Indexes删除不必要的索引Your collection contains unnecessary indexes. Unnecessary indexes consume additional disk space and can degrade write performance.集合包含不必要的索引。不必要的索引会消耗额外的磁盘空间,并可能降低写入性能。
Reduce Bloated Documents减少臃肿的文档Your collection has excessively large documents. The large documents can degrade the performance of your most common queries.集合包含过大的文档。大型文档会降低最常见查询的性能。
Reduce $lookup Operations减少$lookup操作You are running too many $lookup operations on your data. This increases query complexity and reduces query performance.您对数据运行了太多的$lookup操作。这增加了查询复杂性并降低了查询性能。

Details详情

The MongoDB Atlas Performance Advisor (available for M10 clusters or higher) and MongoDB Compass Performance Insights identify schema design anti-patterns in your database. It is important to understand the Atlas anti-pattern warnings in order to properly correct the issues and prevent the use of anti-patterns.MongoDB Atlas性能顾问(适用于M10或更高级别的集群)和MongoDB Compass性能洞察可识别数据库中的模式设计反模式。了解Atlas反模式警告非常重要,以便正确纠正问题并防止使用反模式。

View Schema Suggestions in Performance Advisor在性能顾问中查看架构建议

1

In MongoDB Atlas, go to the Clusters page for your project.在MongoDB Atlas中,转到项目的“集群”页面。

WARNING: Navigation Improvements In Progress导航改进正在进行中 We're currently rolling out a new and improved navigation experience. If the following steps don't match your view in the Atlas UI, see the preview documentation.我们目前正在推出一种新的、改进的导航体验。如果以下步骤与Atlas UI中的视图不匹配,请参阅预览文档

  1. If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.如果尚未显示,请从导航栏的“组织”菜单中选择包含所需项目的组织。
  2. If it's not already displayed, select your desired project from the Projects menu in the navigation bar.如果尚未显示,请从导航栏中的“项目”菜单中选择所需的项目。
  3. If it's not already displayed, click Clusters in the sidebar.如果尚未显示,请单击侧栏中的“集群”。

    The Clusters page displays.将显示“群集”页面。

2

Click the replica set where the collection resides.单击集合所在的副本集。

If the replica set is part of a sharded cluster, first click the sharded cluster containing the replica set.如果副本集是分片集群的一部分,请首先单击包含副本集的分片集群。

3

Click Performance Advisor.单击“性能顾问”。

4

View recommendations.查看建议。

In the Performance Advisor tab, click Explore Recommendations on the Improve Schema card.在“性能顾问”选项卡中,单击“改进架构”卡上的“探索建议”。

5

(Optional) Change which host results to view.(可选)更改要查看的主机结果。

By default, the results correspond to one of the primary hosts. However, you can select another host from the drop-down.默认情况下,结果对应于其中一个主主机。但是,您可以从下拉列表中选择另一个主机。

Learn More了解更多

For recommended schema design patterns, see the following: Schema Design Patterns and Apply Design Patterns.有关推荐的模式设计模式,请参阅以下内容:模式设计模式应用设计模式