MongoDB – Overview

MongoDB – Overview

MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on concept of collection and document.


Database is a physical container for collections. Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases.


Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema. Documents within a collection can have different fields. Typically, all documents in a collection are of similar or related purpose.


A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection's documents may hold different types of data.
The following table shows the relationship of RDBMS terminology with MongoDB.

Database Database
Table Collection
column Field
Tuple/Row Document
Table Join Embedded Documents
Primary Key Primary Key (Default key _id provided by MongoDB itself)
Database Server and Client
mysqld/Oracle mongod
mysql/sqlplus mongo

Sample Document

Following example shows the document structure of a blog site, which is simply a comma separated key value pair.

"_id" : ObjectId("602372d4f7661885eff39c92"),
"userId" : "rirani",
"jobTitleName" : "Developer",
"firstName" : "Romin",
"lastName" : "Irani",
"preferredFullName" : "Romin Irani",
"employeeCode" : "E1",
"region" : "CA",
"phoneNumber" : "408-1234567",
"emailAddress" : "",
"Addresses" : [
"building" : "23 B",
"pincode" : 456789,
"city" : "Los Angeles",
"state" : "California"
"building" : "160 B",
"pincode" : 456789,
"city" : "Chicago",
"state" : "Illinois"

_id is a 12 bytes hexadecimal number which assures the uniqueness of every document. You can provide _id while inserting the document. If you don’t provide then MongoDB provides a unique id for every document. These 12 bytes first 4 bytes for the current timestamp, next 3 bytes for machine id, next 2 bytes for process id of MongoDB server and remaining 3 bytes are simple incremental VALUE.

MongoDB Tutorial (Prev Lesson)
(Next Lesson) MongoDB – Advantages
', { 'anonymize_ip': true });