> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  other tabs: side-panel, drag-drop
-->

# Manage Relationships in Your Compass Entity-Relationship Diagram

MongoDB Compass Readonly Edition will be deprecated in a future release. To replicate the read-only behavior in a standard Compass edition, assign users [`read`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-authrole-read) access at the database level and enable the [readOnly](https://www.mongodb.com/docs/compass/settings/read-only.md#std-label-compass-read-only) option in Compass.

You can manually define relationships between fields across different collections in your Compass entity-relationship diagram.

**Note:**

Relationships are for annotation purposes only. Compass does not store relationship information in your MongoDB database.

## 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.

In addition to specifying collection and field properties for each relationship, you can also specify **cardinality**. In data modeling, cardinality refers to the number of records in one collection that can relate to one or more records in another collection. Cardinality can help you decide whether to [embed](https://www.mongodb.com/docs/manual/data-modeling/embedding.md#std-label-data-modeling-embedding) or [reference](https://www.mongodb.com/docs/manual/data-modeling/referencing.md#std-label-data-modeling-referencing) data in your data model. To learn more, see [Document Relationships.](https://www.mongodb.com/docs/manual/applications/data-models-relationships.md#std-label-data-modeling-relationships)

## Before You Begin

To add relationships, ensure you have already [generated a diagram.](https://www.mongodb.com/docs/compass/data-modeling.md#std-label-compass-data-modeling)

## 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.

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.

A relationship is incomplete if either side is missing a collection or field. Compass displays an incomplete relationship as an animated dashed line in the diagram. The collection node displays a warning that one or more relationships are unresolved. The Relationships tab also displays a  icon next to the relationship. To resolve the warning, verify the linked collections and fields for the relationship.

### 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

- [Export Your Entity-Relationship Diagram from Compass](https://www.mongodb.com/docs/compass/data-modeling/export-diagram.md#std-label-compass-data-modeling-export)

## Learn More

- [Data Modeling in MongoDB Compass](https://www.mongodb.com/docs/compass/data-modeling.md#std-label-compass-data-modeling)
