References in Diagrams for MongoDB

References are the connections between collections, objects or fields that establish how data in source is related to data in target. References can be created in Moon Modeler from collection to collection, from collection to field, or from field to field.

References created in diagrams for MongoDB

How to create references in ER diagram for MongoDB

To create a new reference between two collections, click the Reference button on the main toolbar and then click source and target collections in your ER diagram. In this example, click collection customer and then collection cart.

How to create a new reference in a diagram for MongoDB.

The new reference line appears in the diagram and field customer is added to the target collection cart automatically.

Newly created reference.

In this example we rename the newly created field from customer to customer_id.

Creating references in case a field already exists in the target

Since version 7.5, you can easily model new references by clicking on a column in a source collection and then on a column in a target collection. Moon Modeler automatically uses the existing identifier (or creates a new identifier in the source) and maps the reference to the selected field in the target.

Creating references between existing fields in diagrams for MongoDB

In this case, new field will not be automatically added to the target.

Newly created reference for existing fields.

Alternate identifiers

Alternate identifiers are useful for creating references for fields that you define. In the following scenario, we want to use fields name and surname from the customer collection.

Reference created for custom fields.

How to create a new alternate identifier

To create a new alternate identifier, click the +Add identifier button in section Identifiers.

Creation of a new alternate identifier

Expand the area for the newly created identifier, click +Add field to identifier and select a field. If you wish to add multiple fields to the identifier, just click the +Add field to identifier button again and select another field.

Selection of fields for the new alternate identifier.

How to use alternate identifiers

To use an alternate identifier for a reference, select a reference created between source and target and navigate to section Identifiers.

Selecting the identifier for a reference.

Change the value in the identifier dropdown to the new alternate identifier name. Moon Modeler automatically removes the customer_id field from the target collection and adds there both the fields defined in the alternate identifier: customer_name and customer_surname.

Final visualization of the reference.

Benefits of using references with alternate identifiers

  • When you select a reference, fields in source and target will be highlighted.
  • In the source collection or object, fields included in the alternate identifier have its own purple icon and can be easily recognized.
  • Fields automatically added to the target have its own icon that indicates a linked field.
  • There is no need to add fields to the target first and then do manual mapping. Moon Modeler will create the fields automatically.
  • When you delete a reference, fields from the target can be automatically deleted (this depends on application settings where you can adjust such behavior)

Cardinality

Cardinality settings affect the display of relationships in your diagram. Select a relationship and change values in section Cardinality. Optional child settings change the appearance of line ending to circle.

Related articles

#

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