Why MongoDB use key-value pair and not use row (RDBMS) and use case to use kaey-value pair in MongoDB

Hi every one,

I’m a newbie for MongoDB and i have some confuse about key-value pair in MongoDB

  1. Why MongoDB use key-value pair and not use rows in RDBMS ?
  2. Benefit of key-value pair in MongoDB with row in RDBMS ?
  3. What is the effective of key-value pair in MongoDB? It make to retrieve data using index faster or what ???

Please help me,

Thank you so much!!


There are a lot of advantages. Some of most important are:

  1. You can directly map response from MongoDB to JavaScript objects, so you don’t need any mapping layer in the application.
  2. In RDBMS, all rows need to have all columns defined. So if you want to add new column for some row, all other rows would still get that column, even if it’s empty. In MongoDB, you can add new key/value pairs to specific document, without adding it to other documents.
  3. You can have nested properties and arrays in MongoDB document.

Dear NeNaD,

Thanks for your respone !

So with index in MongoDB, what is benefit of index using key-value pair in MongoDB over with index in RDBMS ?

In MongoDB, indexes optimize the performance of the queries. So if you create an index for some property in a collection, and if you query the collection based on that property, the response would be much faster.

You can create index for many properties in the same collection independently, or even create compound index for multiple properties.

Usually, you will first check your use case and see on which properties you query the collection the most, and you would want to create indexes on these properties to optimize the performance.

We have free courses on the MongoDB University platform - including the MongoDB 101 course - that covers most of the above topics.


PS : It’s 100% free!