Learn how to easily create an ER diagram for MongoDB.
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.
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
- 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.
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.
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.
Another area will expand where you can specify validation settings, field description etc.
Now let’s see how to work documents and hierarchies. If you want to create a document:
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.
2. Then select the field/document in your diagram and add new nested fields or manage existing nested fields on the Children tab. See the following screenshot:
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.
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.
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.
Let’s say the diagram is finished. What other steps can you take in Moon Modeler?