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 database, 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 has a number of 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" : "john.leaf@example.com",
   "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 on the objects, without having to write too many 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.

layouts

Documentation

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, simply 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 and its also interactive. To read the comments, simply hover the collection.

Design a MongoDB schema in a team

DbSchema stores the schema information in local project files. 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 project file, thus making it easier to work on the same project in a team.

Query Tools and Virtual Relations

You can use a set of powerful tools to browse and edit data in your MongoDB database. With Relational Data Browse you’ll be able to browse data from multiple collections at the same time. This is possible via virtual relations, a concept unique to DbSchema, similar to foreign keys.

Using Query Builder, you are able to 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.