What is MongoDB?

Mongo DB is an open source, document-based database based on No SQL for modern applications and cloud based servers. MongoDB is used to build high volume, scalable and performance databases

A document-based or document-oriented database like Mongo DB use JSON like key-value pairs to store data. Mongo DB use collections instead of tables. Each database contains collections ( table in RDBMS ) which contains documents ( columns in RDBMS ). The number of documents in each documents can be different from others.

How Mongodb Stores data in JSON

                "city":"new delhi",

In above example, MongoDB is using one document, i.e.{} to store all data, but for the same query, RDBMS will create two tables, one for user and another for address.


NoSQL ( Not only SQL ) is used to create Non-relational databases , like MongoDB, CouchDB, Redis, Oracle NoSQL. Some blogs describe NoSQL as Non SQL, but actually NoSQL is Not Only SQL.

Some people also says that NoSQL cannot store relationship data. But this term is wrong. Actually NoSQL stores relationship data but can also store non-relational data. This means, NoSQL supports both structures and unstructured data.

NoSQL databases were developed in 2000. NoSQL focus on scalability, performance and simplicity.


Type Relational Non Relational
Schemas Pre Defined Dynamic
Base Table key-value, document, graph
Scability Vertical Horizontal
ACID SupportYesNo ( except Mongo DB)
JoinsRequiredNot Compulsory
Data to Object MappingRequires ORM i.e. (object-relational mapping)Not Required in MongoDB


MongoDB was developed in 2000. JavaScript Developers will learn MongoDB very easily as MongoDB is JSON based. But RDBMS developer might find MongoDB little difficult to understand.

Here is a cheatsheet for SQL to NoSQL.

SQL to NoSQL Cheatsheet
Database Database
SELECT * from tablenamedb.collections.find()
SELECT * from tablename LIMIT 1db.collections.findOne()
CREATE TABLE employee ( name VARCHAR(20))db.createCollection('employee')
INSERT INTO employee VALUES ( avinash)db.employees.insert({name:'avinash'})

MongoDB advantages

The Advantage of MongoDB over RDBMS is that Mongodb is document based, schema less, fast and scalable.

  1. MongoDB is document database. Each collection can have as many documents to store data.
  2. Schema less database. No need to define length of data and datatype.
  3. Scalable very easy to scale.
  4. Document Oriented database that stores data in JSON or BSON
  5. Joins support, but not compulsory.
  6. Powerful Query language.
  7. Full ACID transactions.

MongoDB Commands in Mongo shell

MongoDB Commands in Mongo shell
Command Use
mongod command to start mongodb server
mongo open test database in command prompt
show dbsshow all available Databases
use mydbselect mydb Database. If mydb does not exists, it will create mydb
show collectionsshow all collections in database selected
dbcheck current database
db.mydb.help()show all methods used with database
db.dropDatabase()to drop or delete existing database

Where to use MongoDB

Here are the primary areas where MongoDB is preferred.

  1. Big Data
  2. Content Delivery Management
  3. Unstructured Data
  4. Real Time Analytics
  5. IoT
  6. Mobile Apps
  7. Web Applications

Companies Using MongoDB

List of companies using MongoDB

  1. Facebook
  2. Google
  3. Adobe
  4. Ebay
  5. SAP
  6. Electronics Arts
  7. GOV.UK