For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Data Modeling in MongoDB Compass

Use Compass to create an entity-relationship diagram that visualizes the collections, fields, data types, and relationships in a single database.

Use the following procedure to create your first entity-relationship diagram in Compass.

1

In the left sidebar, click Data Modeling.

2

In the New diagram setup modal, select the connection and database to use. You can create a name for your diagram or use the default name that Compass creates.

3

Select the collections to include in your diagram. If you want Compass to analyze relationships within your collection, make sure the Automatically infer relationships setting is on.

4

Compass generates an entity-relationship diagram with the selected collections and displays the diagram in the current tab.

For detailed instructions and configuration options, see Generate an Entity-Relationship Diagram in Compass.

Consider the data modeling experience in Compass for the following scenarios:

  • Data visualization: Generate an entity-relationship diagram of your current data model. Visualizing your data model can help you identify impacts of potential schema changes across related collections.

  • Data model planning: Track and plan changes to your data structure as your application grows. Model new collections and relationships before you implement them to validate design decisions early.

  • Cross-team collaboration: Share visual representations of your data model with data engineers, product managers, and other stakeholders to ensure everyone understands the current state of your database structure. You can share your data model as an image, JSON file, or .mdm file that can be opened directly in Compass.

  • Application development: Identify inconsistencies, missing relationships, or optimization opportunities in your data model during the development process.

  • Team member onboarding: Quickly understand existing data models when onboarding onto a new project or working with collections created by other teams.

You can add comments to your diagram's collections, fields, and relationships to document definitions or data modeling decisions.

You can define relationships between fields in different collections in your entity-relationship diagram. When you create an entity-relationship diagram, you can opt for Compass to automatically infer relationships. You can also manually add relationships.

Note

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

You can export your Compass entity-relationship diagram. By sharing your diagram, you can collaborate with various teams, receive feedback, and align on final schema design decisions.

You can export your diagram as a:

  • .mdm Diagram File.

  • PNG image.

  • JSON file.

You can also import Compass an entity-relationship diagram that was exported as a .mdm file. By importing an entity-relationship diagram, you can view or edit a diagram shared by a collaborator.

You can view the following general information about your diagram in the Data Model Overview side panel:

  • The database you used to generate your diagram

  • When you first generated the diagram

  • When you last updated your diagram

If you click a collection, the side panel displays information about the collection, including its name, relationships, and custom notes.

If you click a field, the side panel displays information about the field, including its name, data type, and relationships.

Note

To go back to the Data Model Overview from the collection or field view, deselect the collection or field by clicking the empty space in your diagram.

To open the side panel, click the icon.