MongoDB
Discussion Points 
● What is MongoDB 
● Key Features of MongoDB 
● RDBMS & MongoDB 
● Their Behaviour Difference (examples) 
● Embedded vs Reference 
● Advantges and Disadvantages
What is mongoDB 
● MongoDB is an open-source document 
database that provides high performance, high 
availability, and automatic scaling. 
● 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. 
● High Availability 
● To provide high availability, MongoDB’s 
replication facility, called replica sets, provide: 
● automatic failover. 
● data redundancy. 
● A replica set is a group of MongoDB servers 
that maintain the same data set, providing 
redundancy and increasing data availability.
● Automatic Scaling 
● MongoDB provides horizontal scalability as part 
of its core functionality. 
● Automatic sharding distributes data across a 
cluster of machines. 
● Replica sets can provide eventually-consistent 
reads for low-latency high throughput.
● A record in MongoDB is a document, which is a 
data structure composed of field and value 
pairs. MongoDB documents are similar to 
JSON objects. The values of fields may include 
other documents, arrays, and arrays of 
documents.
● The advantages of using documents are: 
● Documents (i.e. objects) correspond to native 
data types in many programming languages. 
● Embedded documents and arrays reduce need 
for expensive joins.
RDBMS 
A Fight With Redundency 
● In relational databases, data modeling typically 
progresses by modeling your data as a series 
of tables, consisting of rows and columns, 
● which collectively define the schema of your 
data. Relational database theory has defineda 
number of ways of putting application data into 
tables, referred to as normal forms.
● The following example defines Normalization 
(1NF) but what if we need to store more data
● SELECT name FROM contacts WHERE phone_numbers LIKE 
'%555-222-2345%'; 
● But now we have a table that’s no longer in first normal form
Denormalizing for Performance 
● The dirty little secret (which isn’t really so 
secret) about relational databases is that 
oncewe have gone through the data modeling 
process to generate our nice nth normal form 
● data model, it’s often necessary to denormalize 
the model to reduce the number of JOIN 
operations required for the queries we execute 
frequently.
Do we need Normalization?? 
● Data doesn’t always have to be tabular, 
basically throwing most of traditional database 
normalization out, starting with first normal 
form. In MongoDB, data is stored in documents. 
● This means that where the first normal form in 
relational databases required that each row-column 
intersection contain exactly one value, 
MongoDB allows you to store an array of 
values if you so desire.
Document Structure 
● The key decision in designing data models for 
MongoDB applications revolves around the 
structure of documents and how the application 
represents relationships between data. 
● There are two tools that allow applications to 
represent these relationships: 
● references and embedded documents.
References 
● References store the relationships between 
data by including links or references from one 
document to another. 
● Applications can resolve these references to 
access the related data. Broadly, these are 
normalized data models.
Embedded Data 
● Embedded documents capture relationships 
between data by storing related data in a single 
document structure. 
● MongoDB documents make it possible to embed 
document structures as sub-documents in a field 
or array within a document. 
● These denormalized data models allow 
applications to retrieve and manipulate related 
data in a single database operation.
Where to use them 
Grounds Embedded Reference 
Locality Yes No 
Atomicity and Isolation Yes No 
Flexibility No Yes 
Potentially High Arity 
Relationship 
No Yes
Blog Example 
With Embedded
With Reference
Advantages & Disadvantages 
● High Performance 
● Models 
● Flexible Schema 
● Solution to complex distributed transactions 
and Join operations 
● RAM limitations
Import/Export 
● mongodump -d knolx -o backup/ 
● mongorestore -d testknol . 
● mongoexport --db knolx --collection testData 
--out test.json 
● mongoimport -d knolx --collection --file 
test.json
References 
● http://docs.mongodb.org/ 
● mongodb applied design patterns
Thank You :)

Introduction to MongoDB

  • 1.
  • 2.
    Discussion Points ●What is MongoDB ● Key Features of MongoDB ● RDBMS & MongoDB ● Their Behaviour Difference (examples) ● Embedded vs Reference ● Advantges and Disadvantages
  • 3.
    What is mongoDB ● MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. ● High Performance MongoDB provides high performance data persistence. In particular, ● Support for embedded data models reduces I/O activity on database system.
  • 4.
    ● Indexes supportfaster queries and can include keys from embedded documents and arrays. ● High Availability ● To provide high availability, MongoDB’s replication facility, called replica sets, provide: ● automatic failover. ● data redundancy. ● A replica set is a group of MongoDB servers that maintain the same data set, providing redundancy and increasing data availability.
  • 5.
    ● Automatic Scaling ● MongoDB provides horizontal scalability as part of its core functionality. ● Automatic sharding distributes data across a cluster of machines. ● Replica sets can provide eventually-consistent reads for low-latency high throughput.
  • 6.
    ● A recordin MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB documents are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents.
  • 7.
    ● The advantagesof using documents are: ● Documents (i.e. objects) correspond to native data types in many programming languages. ● Embedded documents and arrays reduce need for expensive joins.
  • 8.
    RDBMS A FightWith Redundency ● In relational databases, data modeling typically progresses by modeling your data as a series of tables, consisting of rows and columns, ● which collectively define the schema of your data. Relational database theory has defineda number of ways of putting application data into tables, referred to as normal forms.
  • 9.
    ● The followingexample defines Normalization (1NF) but what if we need to store more data
  • 10.
    ● SELECT nameFROM contacts WHERE phone_numbers LIKE '%555-222-2345%'; ● But now we have a table that’s no longer in first normal form
  • 11.
    Denormalizing for Performance ● The dirty little secret (which isn’t really so secret) about relational databases is that oncewe have gone through the data modeling process to generate our nice nth normal form ● data model, it’s often necessary to denormalize the model to reduce the number of JOIN operations required for the queries we execute frequently.
  • 12.
    Do we needNormalization?? ● Data doesn’t always have to be tabular, basically throwing most of traditional database normalization out, starting with first normal form. In MongoDB, data is stored in documents. ● This means that where the first normal form in relational databases required that each row-column intersection contain exactly one value, MongoDB allows you to store an array of values if you so desire.
  • 13.
    Document Structure ●The key decision in designing data models for MongoDB applications revolves around the structure of documents and how the application represents relationships between data. ● There are two tools that allow applications to represent these relationships: ● references and embedded documents.
  • 14.
    References ● Referencesstore the relationships between data by including links or references from one document to another. ● Applications can resolve these references to access the related data. Broadly, these are normalized data models.
  • 16.
    Embedded Data ●Embedded documents capture relationships between data by storing related data in a single document structure. ● MongoDB documents make it possible to embed document structures as sub-documents in a field or array within a document. ● These denormalized data models allow applications to retrieve and manipulate related data in a single database operation.
  • 18.
    Where to usethem Grounds Embedded Reference Locality Yes No Atomicity and Isolation Yes No Flexibility No Yes Potentially High Arity Relationship No Yes
  • 19.
  • 21.
  • 22.
    Advantages & Disadvantages ● High Performance ● Models ● Flexible Schema ● Solution to complex distributed transactions and Join operations ● RAM limitations
  • 23.
    Import/Export ● mongodump-d knolx -o backup/ ● mongorestore -d testknol . ● mongoexport --db knolx --collection testData --out test.json ● mongoimport -d knolx --collection --file test.json
  • 24.
    References ● http://docs.mongodb.org/ ● mongodb applied design patterns
  • 25.