How to create an ER diagram for MongoDB

Learn how to easily create an ER diagram for MongoDB.

Diagram for MongoDB created in Moon Modeler

Creating a project

We’ll start by creating a new project in Moon Modeler. To create a new project click the New button on the toolbar or navigate to Projects and click the New Project button.

New project for MongoDB

A new modal form will open. Select the MongoDB type, specify name and click Create new project.

Now you can begin modeling the database structure. You can add the following MongoDB specific items to your project.

  • Collections & documents
  • References
  • Other objects like views and functions

Adding collections to your ER diagram for MongoDB

To add a new collection to the project click the Collection button on the toolbar and then click the main area of the diagram.

Adding collections to your ER diagram

A new graphical representative appears in the diagram. You can edit the properties of the collection through the panel on the right side where you can easily enter all the necessary settings.

In the Collection specifics section you can specify the collection settings for example validation level, validation action etc.

Collection specifics in ER diagram for MongoDB.

Adding fields to collections

In the Fields section you can add new fields to collections according to your schema design. Enter the name of the new field, the data type and click Add. The newly added field will be displayed in the side panel and also immediately in the diagram.

To get to the area where you can edit the specifics of a field click the arrow icon to the left of the field name.

Field specifics

Another area will expand where you can specify validation settings, field description etc.

Creating hierarchical structures

Now let’s see how to work with contained objects:

1. Add a new field to your collection and choose the object data type. Note: You can also select an existing field and change the data type from e.g. string to the object data type.

How to create a contained object by  selecting the object data type.

2. Then select the object in your diagram and add new fields or manage existing fields on the Fields tab. See the following screenshot:

How to manage fields that belong to a contained object.

Creating references in ER diagram for MongoDB

References are represented by specific links between collections. To create a new reference click the Reference icon on the toolbar and then click the parent and child collections in the diagram.

Button for adding new reference to your ER diagram for MongoDB

Now we can change the properties of the reference. For example, change the cardinality and modify the one-to-many type to one-to-one or many-to-many, or define cardinality captions.

MongoDB - reference properties

The cardinality captions can be displayed directly in the diagram.

Adding views to ER diagram for MongoDB

To add a view to the diagram, click the Other icon on the main toolbar, choose Add View item from the sub-menu and then click the main diagram area.

Adding a view to ERD

Other actions

Let’s say the diagram is finished. What other steps can you take in Moon Modeler?

MongoDB validation script

#

DATA MODELING TOOLS
DRAW Diagrams and
GENERATE Scripts
Download data modeling tools
Blog Categories
Blog by Platforms