MongoDB Visual Design

MongoDB is one of the fastest-growing databases in the market. It offers great flexibility by focusing on a unique approach in the way they store data. MongoDB uses a JSON-like format that can contain different kinds of structures. Two documents from the same collection can have different fields or references.

By using this kind of storage, MongoDB is known for being a schemaless, because it doesn’t impose any constraints on the database objects. This is the main feature that offers so much flexibility and scalability for MongoDB.

Being schemaless has its disadvantages. Working with a big schemaless database will impose a higher degree of complexity. This can make it harder for you to manage data in MongoDB because it requires a lot of knowledge. Working with complementary tools such as DbSchema can help you visualize the MongoDB diagram and overcome this problem.

Create a visual schema for MongoDB

Even though MongoDB doesn’t have a traditional schema, there is a way to deduce it. A collection several objects. No matter how different, every object has a name and an ID that can be referenced in other objects. Let’s take a look at an example:

 > db.persons.findOne()
   "first_name" : "John",
   "last_name" : "Leaf",
   "email" : "",
   "address" : [
       "city_id" : 3,
       "street" : "Seaseme St",
       "number" : 12,
       "zip" : 123555

This is an example of a JSON object from the ‘persons’ collection. This has an embedded object named “address”, that also has it’s particular fields. When DbSchema connects to MongoDB, it searches every object in the schema and looks for similarities. In this case, the collection for this particular object will look like this:

persons collection

As you can see in the image above, DbSchema created a collection for the “persons” object, including the embedded “address” object. The “_id” field from “persons” was autogenerated by MongoDB.

Managing the schema

Once the diagram was created, the possibilities are endless. The database can be edited just by clicking the objects, without any queries. You can split the database in multiple layouts, each focused on a specific part of the database. For example, you can create a layout for the “persons” collection, one for “product collection”, and one for “countries” collection.



If you want to document the database, all you have to do is double click on a collection or a field and add a comment. If you want to add a more general comment, then add a callout on the diagram.
The virtual diagram can be exported to documentation in HTML5 or PDF formats. It will include all the comments and callouts. The documentation can be opened with any browser. To read the comments, hover the collection with the mouse.

Design a MongoDB schema in a team

DbSchema stores the schema information as a model file. This enables you to work on the “schema” without database connection & synchronize it later.
It is also possible to compare & synchronize two different versions of the same model file, thus making it easier to work on the same model in a team.

Query Tools and Virtual Foreign Keys

You can use a set of powerful tools to browse and edit data in your MongoDB database. The Relational Data Editor helps you to visualize data from multiple collections at the same time. This is possible via virtual foreign keys, a concept unique to DbSchema.

Using Query Builder, you can create visual queries without using the complex MongoDB native language. If you want to write queries manually, you can always do this by using the Query Editor, specially designed for MongoDB.

Share this blog post on Twitter, Facebook, and LinkedIn