Data modeling is the process of visually creating a graphical representation of a system or database. In the case of relational databases, we can mention the creation of entity-relational diagrams in which entities, attributes and relationships between entities are displayed. (Read more information about ER diagrams).
Advantages of data modeling
- Fewer design and development errors
- Easy and fast design, especially in the early stages of development
- Better communication between team members
- Time saving
- Lower development costs
- and many others
MongoDB schema design and noSQL database modeling
But what is the advantage of data modeling when we talk about noSQL databases? The advantage of many “schema-less” databases is that they are very flexible and it is not necessary to have a precise database structure. The popularity of database systems such as MongoDB is obvious, and when it comes to the flexibility of saving data, this is certainly one of many key features.
So why focus on data modeling?
Recall that one of the benefits of data modeling is the description of structure, the creation of documentation. A data model is used for better communication within the development team. Therefore, having a well-described database structure is very useful.
Imagine how you store your clothes. Having one big closet where all the clothes will be placed indiscriminately is possible. However, finding the piece of clothing you need may not be so easy. Some information on clothing organization could be beneficial, right?
Is there the best noSQL data model?
Of course, the design of the database structure depends on your needs, on whether you need to read the data frequently or only rarely. Whether you need to achieve a certain performance, etc. There are a number of options for how to store the data and how to model the schema. For example, in MongoDB you can create multiple collections and use references, or insert data into a selected collection as nested documents. Which way is more convenient? Try to model both and discuss with your colleagues. Yes, you ou can also use a data modeling tool for noSQL databases like Moon Modeler for this purpose.
Other advantages: if you work with the MongoDB database, you can use the schema validation. A feature that ensures that data will only be stored if it is in the expected format.
NoSQL database design examples
Here you can see the model created for MongoDB. It contains three collections linked by references.
Another option is to embed documents into the collection.
Benefits of using flexible data structures in relational databases
Even in open source database systems like PostgreSQL we can store data without a predefined structure. For example, we can use the JSON data type and store information in it according to our needs. If you are working with a relational database in this way, Moon Modeler can be useful in this case too, as it supports visualization of JSON data types in an ER diagram.
If you look at the image below, there is a contact column in the customer table. It is a JSON data type. Similar is the case with the order table and the item column.