
Here, the child data is embedded in the parent key ‘car’, if you want to get the data from the name of the person, then embedding would be better to use, as you only have to provide a single query to get the child data as well. Suppose, a person can have multiple cars, for this, we can create relationships using embedding or referencing. One to ManyĪ one-to-many relationship is having a one-key of parent document with embedded or referenced child documents, creating a 1:N relationship. Here, the user’s passport details are embedded in the passport key, there is no need to create a separate collection until and unless the data is quite large. For example, one person can have only one passport. One parent key with one embedded child document creates a 1:1 relationship. One-to-one is the most fundamental relationship to define. Let’s look into the types of relationships One to One You can set up the relationship based on the need for your data and the performance of the query. This is not such as normalizing into tables but creating through embedded and referenced relationships. Relationships represent how the multiple documents are logically connected in MongoDB to create a more manageable database.

Following are the key things that need to be considered while building a schema MongoDB data modeling depends upon the data that your application needs. Look into the example below.ĭata is normalized into tables and are joined using the foreign key concepts. The relationship is built by normalizing the data into multiple tables to remove redundancy and any data can be fetched according to the query we provide i.e using join. Relational databases provide a good grasp of defining relationships which helps devs in only focusing on the data they have while building schema. You must first know how your application wants the data, for that let's first look into the approaches between Relational databases and MongoDB databases. Now, while defining schema across multiple databases most devs think that the approaches are similar, we store the data and then apply queries to fetch the same, well this is not how it works, schema is designed according to how we query the data and the functionality provided by the databases.

Schema Design Approaches – Relational vs MongoDB

MongoDB is a document-oriented NoSQL database that can store large amounts of data in a JSON format in a collection and has a dynamic schema. This article will help you understand the theoretical core concepts of MongoDB that can be used to improve scalability and performance along with the types of schema that can be defined. Thus, keeping this in mind, a good schema design practice is needed. Unwanted schema objects may not impact your database at earlier stages but with the increasing amount of data, querying can slow down the performance and will acquire more memory. Can define the schema in an object format as you want.Ī well-defined schema is very much important in MongoDB to query the data more efficiently with less hustle and improve the scalability as well.Unlike relational databases, it may not provide techniques for defining good relationships but it provides flexibility in defining the schema of our collection, which is one of the core advantages of the platform. MongoDB has been a popular database among all NoSQL databases used these days for storing big data.
