Introduction to MongoDB

1. Introduction

MongoDB is an open-source document database. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas. MongoDB is developed by MongoDB Inc. and is free and open-source, published under a combination of the GNU Affero General Public License and the Apache License. The software company 10gen began developing MongoDB in 2007 as a component of a planned platform as a service product. In 2009, the company shifted to an open source development model, with the company offering commercial support and other services. In 2013, 10gen changed its name to MongoDB. It provides high performance, high availability, and automatic scaling.

1.1 High performance

MongoDB provides high performance data persistence. In particular,

  • Support for embedded data models reduces I/O activity on database system.
  • Indexes support faster queries and can include keys from embedded documents and arrays.

1.2 High Availability

To provide high availability, MongoDB’s replication facility, called replica sets, provide:

A replica set is a group of MongoDB servers that maintain the same data set, providing redundancy and increasing data availability.

1.3 Automatic Scaling

MongoDB provides horizontal scalability as part of its core functionality.

  • Automatic sharing distributes data across a cluster of machines.
  • Replica sets can provide eventually-consistent reads for low-latency, high throughput deployments.

2. Downloading and Installing MongoDB

The Free & commercial version of MongoDB could be downloaded by clicking here

Step by installation guide for various platforms can be obtained by clicking here
(This one if for windows)

3. Major Components of MongoDB Distributions

Component Set Binaries
Server mongod.exe
Router mongos.exe
Client mongo.exe
MonitoringTools mongostat.exe,mongotop.exe
ImportExportTools mongodump.exe,mongorestore.exe,mongoexport.exe,mongoimport.exe
MiscellaneousTools bsondump.exe,mongofiles.exe,mongooplog.exe,mongoperf.exe

4. Introduction to NoSQL

A NoSQL (originally referring to “non SQL”, “non relational” or “not only SQL”)database provides a mechanism for storage and retrieval of data which is modeled in means other than the tabular relations used in relational databases.Motivations for this approach include: simplicity of design, simpler “horizontal” scaling to clusters of machines (which is a problem for relational databases), and finer control over availability. The data structures used by NoSQL databases (e.g. key-value, wide column, graph, or document) are different from those used by default in relational databases, making some operations faster in NoSQL

Table store rows while MongoDB stores documents. MongoDB documents are JSON Objects which may include other documents, arrays and arrays of documents.

But how does it Store ?
The Answer is: BSON

5. Overview of JSON

5.1 So What is JSON?

JSON stands for JavaScript Object Notation. It is a syntax for storing and exchanging data. This is an easier alternative to use XML

5.2 So Why prefer JSON?

It is a lightweight data-interchange format as well as is language independent i.e. it uses only key pair relationship. JSON is “self-describing” and easy to understand

5.3 JSON Object Syntax


JSON Object Syntax in MongoDB


Sample JSON Object:
     "firstname" : "parth",
     "lastname" : "joshi"


5.4 JSON Array Syntax


JSON Array syntax in MongoDB


Sample JSON Object:
            "firstName": "John",
            "lastName": "Doe"
            "firstName": "Anna",
            "lastName": "Smith"
            "firstName": "Peter",
            "lastName": "Jones"


5.5 JSON Value Syntax

JSON Syntax values in MongoDB

5.6 How is JSON used in conventional web services?

JSON makes data interchanging simpler as packets are made as compact as they viably can. JSON is easy to integrate in JavaScript applications, making it a a preferred data format with many mobile application developers. This gives the benefit to store data in form of JSON.

The Request-Response JSON pattern is very similar to that of XML based web services. The web service is implemented using a program. The input and output data formats are described using language structures and framework is responsible for transforming incoming JSON messages into application data, and linking to the application. The application returns output data back to the framework and transforms this into JSON data to return to the client.

Using JSON in Web Client serivces

6. RDBMS Vs. MongoDB

RDBMS (MySQL, Oracle, etc) MongoDB
Table Collection
Row Document
Column Field
Joins EmbeddedDocuments. Linking