Getting started with MongoDB

Reading Time: 3 minutes

Hi everyone! in this blog, I will try to explain what is MongoDB and why to use MongoDB

What is MongoDB?

MongoDB is one of the powerful NoSql DataBase. It does not use the usual rows and columns that we are so much associated with the relational database management. It is an architecture that is built on collections and documents.
This database uses a document storage format called BSON which is a binary style of JSON style documents.

  • It is Document-Oriented NoSQL database
  • It is Schema free database and Based on Binary JSON format which is called BSON
  • It stores the data in the collection which is simply a group of Documents
  • It has the Auto-Sharding feature in order to scale horizontally

Let’s explore and see how it is different from RDBMS

Database Database
Table Collection
Row Document
Colum Field

From above table, it is very much clear that how MongoDB is organized in Document format comparison with RDBMS.
MongoDB basically stores the data in a key-value pair which is JSON format which is specially designed for transferring data over the network. You can have fields of the different data types in one document, it does not force you to have the same data type for all the fields in the document. With MongoDB, this is the advantage that you can insert any kind of data, but this data should be in form of JSON format.

Now let’s understand the Architecture of MongoDB –

Database  ->  Collection  -> Document


  • A Database is a container of your collections.
  • A single MongoDB server typically has multiple databases.


  • A collection is basically a group of Documents.
  • It is similar to the table in RDBMS


  • The document is Basically a set of key-value pair
  • In one Document you can have a different kind of data
  • You can insert the same field with different data type

How primary key plays differently Role as compare to RDBMS:- 

In RDBS, as we are very well aware of Primary Key, that is basically used for uniquely identifies the data and we explicitly set the column as the primary key.

In RDBMS, there is no limitation, any column can be part of the primary key

But if we talk about the primary key in MongoDB, the field_id  is reserved for the primary key. When we insert the data without filed _id then MongoDB sets the value of it as the unique number by itself to uniquely identify the data.

If you want to set the primary key for your document then you need to set the value if field _id as the primary key. So basically in MongoDB, field _id  plays the role of the primary key

let’s take an example of MongoDB document –

name:"shubham agrawal",

This is the simple example of MongoDB document, Here you can see field _id which is a primary key of this document.

Why use MongoDB?

  • Data is stored in the form of JSON style documents.
  • Auto-sharding
  • Replication and high availability
  • Rich queries
  • Index on any field

I hope now you will have some basic idea of MongoDB. In my next blog, I will explain the operations on MongoDB


Written by 

Shubham is a Software Consultant, with experience of more than 1.5 years.He is familiar with Object Oriented Programming Paradigms. He is always eager to learn new and advance concepts. Aside from being a programmer, his hobbies include playing badminton,watching movies, writing blogs. He has experience working in C, C++, CoreJava, Adv Java, HTML, CSS, JS, Ajax.

1 thought on “Getting started with MongoDB3 min read

Comments are closed.