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

# Generate an Entity-Relationship Diagram in Compass

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.

Generate a visualization of your data model as an entity-relationship diagram in Compass. Entity-relationship diagrams can help you understand and document the relationships between data in your database and plan changes to your schema.

## About this Task

If you make any changes to your data after you generate a diagram, Compass does not automatically update the diagram. You must create a new diagram to see your changes.

## Before You Begin

To generate an entity-relationship diagram in Compass, your database must have at least one collection with data.

## Steps

1. Open the Data Modeling tab

   In the left sidebar, click  Data Modeling.

2. Click Generate diagram

   If you have existing diagrams saved in the Data Modeling tab, you can create a new diagram by clicking  Generate new diagram in the upper-right corner of the screen.

3. Set up your new diagram

   In the New diagram setup modal:

   - Select which MongoDB connection to use to generate your diagram.

   - Select which database to use for your data model diagram.

   - Input a name for your diagram.

   After you specify each field, click Next.

4. Select collections

   Use the checkboxes to select which collections to include in your data model diagram. You can also use the search bar to filter for specific collections.

   After you select your collections, click Next.

5. *(Optional)* Toggle automatically inferred relationships

   In the Diagram Settings modal, you can choose to Automatically infer relationships between collections. When enabled, Compass analyzes the selected collections and adds relationships based on indexed fields that contain references to other collections.

   You can also [manually add and edit relationships](https://www.mongodb.com/docs/compass/data-modeling/relationships.md#std-label-compass-data-modeling-relationships) after you generate your diagram.

   **Note:**

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

6. *(Optional)* Configure document sampling

   In the Diagram Settings modal, you can specify how many documents Compass samples from your collections to generate your diagram. By default, Compass samples 100 documents per collection.

   Larger sample sizes improve accuracy but may increase analysis time and memory usage. Smaller sample sizes decrease analysis time and memory usage but may miss infrequent fields or relationships.

   You can also select whether you want to generate a diagram that samples all documents in your collections. Consider the size of your dataset and available resources on your device before you select All documents.

7. Click Generate

   Compass generates an entity-relationship diagram with the selected collections and displays it in the current tab. Compass also displays the Data Model Overview [side panel](https://www.mongodb.com/docs/compass/data-modeling.md#std-label-compass-dm-side-panel) where you can rename your diagram and view the following information:

   - The database you used to generate your diagram

   - When you first generated the diagram

   - When you last updated your diagram

   After you generate a diagram, Compass displays the existing diagrams in the Data Modeling tab.

   **Note:**

   If you click a collection or field in your diagram, the side panel displays information about the collection or field. To go back to the Data Model Overview, deselect the collection or field by clicking the empty space in your diagram.

## Next Steps

- [Manage Relationships in Your Compass Entity-Relationship Diagram](https://www.mongodb.com/docs/compass/data-modeling/relationships.md#std-label-compass-data-modeling-relationships)

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

- [Import an Entity-Relationship Diagram in Compass](https://www.mongodb.com/docs/compass/data-modeling/import-diagram.md#std-label-compass-data-modeling-import)

## Learn More

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

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