MongoDB Data Model Designs

For modeling data in MongoDB, two strategies are available. These strategies are different and it is recommended to analyze scenario for a better flow.

The two methods for data model design in MongoDB are:

  1. Embedded Data Model
  2. Normalized Data Model

1. Embedded Data Model

This method, also known as the de-normalized data model, allows you embedd all of the related documents in a single document.

These nested documents are also called sub-documents.

Embedded Data Model example

If we obtain student information in three different documents, Personal_details, Contact, and Address, we can embed all three in a single one, as shown below.

{
_id: ,
Std_ID: "987STD001"
Personal_details:{
First_Name: "Rashmika",
Last_Name: "Sharma",
Date_Of_Birth: "1999-08-26"
},
Contact: {
e-mail: "rashmika_sharma.123@gmail.com",
phone: "9987645673"
},
Address: {
city: "Karnataka",
Area: "BTM2ndStage",
State: "Bengaluru"
}
}

2. Normalized Data Model

In a normalized data model, object references are used to express the relationships between documents and data objects. Because this approach reduces data duplication, it is relatively simple to document many-to-many relationships without having to repeat content.

Normalized data models are the most effective technique to model large hierarchical data with cross-collection relationships.

Normalized Data Model Example

Here we have created multiple collections for storing students data which are linked with _id.

Student:

{
_id: <StudentId101>,
Std_ID: "10025AE336"
}

Personal_Details:

{
_id: <StudentId102>,
stdDocID: " StudentId101",
First_Name: "Rashmika",
Last_Name: "Sharma",
Date_Of_Birth: "1999-08-26"
}

Contact:

{
_id: <StudentId103>,
stdDocID: " StudentId101",
e-mail: "rashmika_sharma.123@gmail.com",
phone: "9987645673"
}

Address:

{
_id: <StudentId104>,
stdDocID: " StudentId101",
city: "Karnataka",
Area: "BTM2ndStage",
State: "Bengaluru"
}

Data Modelling in MongoDB

Data modeling in MongoDB is the process of designing and creating the structure of collections and documents that will be stored in the database.

Maintaining data in an organized manner is very important for database efficiency. It also ensures data security, data accuracy, and better functioning. To maintain an organized database, it is important to learn data modeling.

In this article, we will go through MongoDB data modeling with examples and explore MongoDB’s features and capabilities.

Similar Reads

What is Data Modeling in MongoDB?

MongoDB Data modeling is the process of arranging unstructured data from a real-world event into a logical data model in a database....

MongoDB Data Model Designs

For modeling data in MongoDB, two strategies are available. These strategies are different and it is recommended to analyze scenario for a better flow....

Advantages Of Data Modeling in MongoDB

Data modeling in MongoDB is essential for a successful application, even though at first it might just seem like one more step. In addition to increasing overall efficiency and improving development cycles, data modeling helps you better understand the data at hand and identify future business requirements, which can save time and money....

Considerations While Creating Data Model Design in MongoDB

Some important points to consider while creating a data model for MongoDB database are:...

Conclusion

MongoDB Data modeling is a fundamental component of database development. In this article, we explored the best practices for designing a highly effective and scalable data model in MongoDB....

MongoDB Data Modeling – FAQs

What is data modeling in MongoDB?...

Contact Us