Docs Home / Compass / Data Modeling

Manage Relationships in Your Compass Entity-Relationship Diagram管理Compass实体关系图中的关系

You can manually define relationships between fields across different collections in your Compass entity-relationship diagram.您可以在Compass实体关系图中手动定义不同集合中字段之间的关系。

Note

Relationships are for annotation purposes only. Compass does not store relationship information in your MongoDB database.关系仅用于注释目的。Compass不会将关系信息存储在MongoDB数据库中。

About this Task关于此任务

You can manually add relationships to your entity-relationship diagram by using one of the following methods:您可以使用以下方法之一手动将关系添加到实体关系图中:

  • Side Panel: Manually add a relationship by selecting a source collection.侧面板:通过选择源集合手动添加关系。
  • Drag and Drop: Create a relationship by clicking and dragging from one collection to another.拖放:通过单击并从一个集合拖动到另一个集合来创建关系。

Before You Begin开始之前

To add relationships, ensure you have already generated a diagram.要添加关系,请确保您已经生成了图表

Steps步骤

To learn how to add relationships to your entity-relationship diagram, select the tab corresponding to your preferred method:要了解如何将关系添加到实体关系图中,请选择与首选方法对应的选项卡:

Side Panel侧面板
1

Open your entity-relationship diagram打开实体关系图

From the Data Modeling tab, open your entity-relationship diagram.在“数据建模”选项卡中,打开实体关系图。

2

Open the collection side panel打开集合侧面板

Click one of your collection nodes in the diagram. The collections side panel opens on the right side of the screen.单击图表中的某个集合节点。集合侧面板在屏幕右侧打开。

3

Click Add Relationship单击添加关系

In the side panel's Relationship tab, click Add Relationship.在侧面板的“关系”选项卡中,单击“添加关系”。

4

Specify Relationship Properties指定关系属性

Specify values for the following fields under Relationship Properties:在“关系属性”下为以下字段指定值:

  • Local collection: The primary collection in the relationship.本地集合:关系中的主集合。
  • Local field: The field in the primary collection.本地字段:主集合中的字段。
  • Local cardinality: The number of unique values in the local field.本地基数:本地字段中唯一值的数量。
  • Foreign collection: The target collection in the relationship.外部集合:关系中的目标集合。
  • Foreign field: The field in the target collection.外部字段:目标集合中的字段。
  • Foreign cardinality: The number of unique values in the foreign field.外部基数:外来字段中唯一值的数量。

Compass automatically saves and updates your changes as you make them.Compass会在您进行更改时自动保存和更新更改。

5

Add annotations for your relationship为关系添加注释

In the side panel's Notes tab, you can add annotations for your relationship. This can be helpful for documenting the purpose and details of the relationship.在侧面板的“注释”选项卡中,您可以为关系添加注释。这有助于记录关系的目的和细节。

Drag and Drop拖放
1

Open your entity-relationship diagram打开实体关系图

From the Data Modeling tab, open your entity-relationship diagram.在“数据建模”选项卡中,打开实体关系图。

2

Click the icon单击图标

In the upper-left corner of the diagram view, click the icon to enable drag-and-drop relationship creation.在图表视图的左上角,单击图标以启用拖放关系创建。

3

Click one collection and drag it to another单击一个集合并将其拖动到另一个集合

When you click a collection and drag it to another, Compass opens the side panel and displays the Relationship Properties tab.当您单击一个集合并将其拖动到另一个集合时,Compass会打开侧面板并显示“关系属性”选项卡。

4

Specify Relationship Properties指定关系属性

Specify values for the following fields under Relationship Properties:在“关系属性”下为以下字段指定值:

  • Local collection: The primary collection in the relationship.本地集合:关系中的主要集合。
  • Local field: The field in the primary collection.本地字段:主集合中的字段。
  • Local cardinality: The number of unique values in the local field.本地基数:本地字段中唯一值的数量。
  • Foreign collection: The target collection in the relationship.外部集合:关系中的目标集合。
  • Foreign field: The field in the target collection.外部字段:目标集合中的字段。
  • Foreign cardinality: The number of unique values in the foreign field.外部基数:外来字段中唯一值的数量。

Compass automatically saves and updates your changes as you make them.Compass会在您进行更改时自动保存和更新更改。

5

Add annotations for your relationship为关系添加注释

In the side panel's Notes tab, you can add annotations for your relationship. This can be helpful for documenting the purpose and details of the relationship.在侧面板的“注释”选项卡中,您可以为关系添加注释。这有助于记录关系的目的和细节。

After you create a relationship, Compass displays each relationship in the Relationships tab.创建关系后,Compass会在“关系”选项卡中显示每个关系。

Delete Relationships删除关系

To delete a relationship from your entity-relationship diagram:要从实体关系图中删除关系,请执行以下操作:

1

Open the relationship side panel打开关系侧面板

Click on the relationship in the diagram. The relationship side panel opens on the right side of the screen.单击图表中的关系。关系侧面板在屏幕右侧打开。

2

Select the relationship to delete选择要删除的关系

In the Relationship Properties tab, click the Delete button.在“关系属性”选项卡中,单击“删除”按钮。

Next Steps后续步骤

Learn More了解更多