Data relations in Mingo
When documents reference each other, they usually do so by the _id of the referenced document. There are several types of document relations (such as one-to-many, one-to-one, many-to-one, many-to-many), but we can generally say that there is always a parent document (the one referencing) and a child document (the one being referenced).
For example, you could have the following document in Orders referencing a document in Users collection:
{
_id: new ObjectId("8cc43bb95dd51baa970ae4ad"),
user: new ObjectId("51baa970ae4ad8cc43bb95dd")
}
{
_id: new ObjectId("51baa970ae4ad8cc43bb95dd"),
firstname: 'John',
lastname: 'Smith'
}
When you are viewing the Orders collection, the ObjectId("51baa970ae4ad8cc43bb95dd")
does not say much to you. It would be much more preferable to see that it is actually John Smith.
Mingo's aproach to the problem
To make your data more readable, Mingo analyzes possible data relations within a database and shows more human information about the referenced documents and the relation itself.
Mingo searches through samples of documents from each collection and identifies fields that look like an _id. Then it tries to find those _id's in the database. When found, it creates a relation and guesses the best field to show as a preview. In the example above, the document references the Schools collection document and the "name" field was chosen to be the preview value.
The same relation is then shown in the referenced document:
Relations are automatically analyzed upon first connect to the database.
Managing data relations
Usually, there is very little you have to do for relations to work properly in Mingo. To view the currently known relations, right-click the database in the sidebar and select Data Relations:
The list of Data Relations will be shown:
In the above screenshot, the first relation means the following: Documents from the Billing collection reference by the field "school_id" documents in the Schools collection. The "name" field in the Schools collection was chosen to show a more human value.
Add a new relation
Mingo let's you add a new relation in the list of relations (mentioned above) or gives you the opportunity to do so when it guesses a field is an _id, but there is no relation set so far:
Edit an existing relation
To edit a relation from the list of data relations, just click the pencil icon. You can also edit the relation where the preview is shown in the documents. Just click the cog icon.
Follow the instructions in the modal to update or remove the relation.
The last checkbox is worth mentioning: "Update all preview paths for 'Schools' to 'name'". This allows you to update the preview field for collection in all existing relations at once. It is very handy when you have several relations poiting to the same collection.
Delete an existing relation
To delete a relation from the list of data relations, just click the trash icon. You can also delete the relation where the preview is shown in the documents. Just click the cog icon and press the delete button in the bottom left corner of the modal.
Other considerations
Extra information is requested from the database to show the related document's preview field. Mingo is optimised to do this efficiently, but if you have many relations, it could have performance implications. If this negatively affects your user experience or puts a burden on your server, minimize the number of relations to those you really need. You can also delete them all completely.
Mingo's algorithm analyzing the relations is not perfect if your data is not consistent or you use very specific values for your _ids. In such case, we recommend setting your relations manually.
The preview fields are selected automatically by Mingo using simple criteria. In case an inappropriate field is selected, you can edit the relation and update the preview field manually.