Radoslav Toth
June 8, 2022

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.

Human readable info about the document that is being referenced.

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:

List of data relations within a database

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.

Read more

MongoDB NodeShell

Mingo's NodeShell let's you execute JavaScript code to work with data directly in Mingo. This is NOT MONGO SHELL, though. The command must be a regular async JS function with a return value. This allows complex code with loops, conditions and variable initialization to be executed. This code must be a definition of a async function and […]
Radoslav Toth

Compare and sync entire MongoDB databases 

Do you ever need to download the production DB to your localhost for development purposes? Or just sync changes from one DB to another? This can be done using Mingo’s Compare & Sync tool. You don’t need to write scripts or use the terminal mongodump / mongorestore functions, anymore. With Mingo’s Compare & Sync tool […]
Radoslav Toth

Mingo’s keyboard shortcuts

We are all tired of new shortcuts we have to learn. Mingo’s shortcuts mimic what you are already used to from a browser or your dev tool. However, Mingo also has some new intuitive “hovering” shortcuts. Just hover over a document and press space or X to select the document. Or hover a document and CMD+C / CTRL+C to copy document value.  To […]
Radoslav Toth

Smart search

The majority of queries we execute on MongoDB collections are very simple. We usually search for an _id, an email or username and we do this many times over every day. To make such searches simple and fast, Mingo provides a few great hacks for you. Value as query First of all, indexed fields can […]
Radoslav Toth

5 best MongoDB GUI in 2022

What is a MongoDB GUI client? MongoDB GUI is a graphical interface for MongoDB. It provides a way to view and manipulate data in MongoDB databases using the MongoDB API or MongoDB Shell. As you may know, you can query your data through the command line, but this gets messy and you can get easily […]
daviddurika

MongoDB aggregations for beginners

MongoDB's aggregation is one of the most powerful tools in the database, allowing you to perform complex data analysis on large datasets. This article will show you how to use aggregation to create powerful data aggregations. Basic aggregations An aggregation is a powerful tool for data analysis. It allows you to perform complex queries on […]
daviddurika

Download Mingo now

The best MongoDB GUI Admin. Intuitive • Fast • Secure
Download Now