If you have developed some application, you might have used some relational database like Oracle, MySQL or PostgreSQL. Though relational databases have their benefits, with increased use of internet and social media these solutions lack flexibility and becoming less viable. Just consider some blog post is having some comments, tags, author info, likes, and shares. To store all this data in relational tables, we need the complicated structure of multiple tables. Also, we have to perform many joins while getting this information out from the database. This is where MongoDB is convenient. MongoDB is Document store meaning it stores data in documents instead of rows. So in above example instead of having data in multiple tables, in MongoDB, it is stored in the single document in JSON (JavaScript Object Notation) format.

MongoDB Documents

Consider following example document stored in MongoDB

MongoDB

This image shows document representing interests of the person named Smith. As you can see this is set of properties and their values which can be described in simple data structures like strings and numbers.  As shown by 2,  values can be another JSON document, or they can be arrays of values shown by property 3. There is _id filed pointed by 1 which is present in each document in MongoDB. This field acts as a primary key the in the database. We will learn more about -id filed in future articles.

MongoDB documents do not need to have a fixed structure. Lack of an enforced schema is beneficial when we need to add a new field on the go. Consider that we need to add an email field to above structure. We can do that quickly by adding “email”: “value” pair to document. We do not need to change existing documents in this case.

MongoDB also provides replication. We can horizontally scale MongoDB very easily. It also provides secondary indexes. We can add up to 64 indexes to each document. All these features made MongoDB very popular.

In next few articles, We will explore the features of MongoDB along with how to query on the database and integrate MongoDB using Java and python. Till then happy learning :).

I am passionate about data analytics, machine learning, and artificial intelligence. Recently I have started blogging about my experience while learning these exciting technologies.

Leave a Reply

Close Menu