3. Database Evolution
Flat Files RDBMS NoSQL MongoDB
1970s: data stored in flat
file system
1979: a standard
way of query the
data - what do we
want to query,
how to process
that query but
1998:
1. Key-value Store
2. Tabular
3. Document oriented
(MongoDB, CouchDB,
etc.)
2009: Free & Open
Source, Cross-
Platform, Document
Oriented
Problem:
no standard
implementation
Problem: with the
big n huge amount
data
Problem: Less support
for Complex Queries
Solution: Relational
Database
Solution: NoSQL Solution: Use Third-
Party GUIs
3
4. Features
Expressive Query Language & Secondary Indexes
Strong Consistency
Flexibility
Scalability & Performance
4
5. General
Purpose
MongoDB is:
Easy to Use
Fast &
Scalable
Sophisticated query
language
Full featured indexesRich data model
Simple to setup and
manage
Native language drivers
in all popular languages
Easy mapping to
object oriented code
Dynamically add /
remove capacity with no
downtime
Auto-sharding built in
Operates at in-memory
speed wherever
possible
6. Comparisons
RDBMS MongoDB
Relational database Document-oriented database, non
relational
Schema based database, follow joins Schema-less database, references and
$lookup
Data stored in tables (tables contain
collection of rows)
Data stored in form of collection (collection
contain group of object document)
No horizontal scaling
Eg. 1st row has 5 column then 2nd row
must have 5 column for the given table
Horizontal scaling
Eg. 1st row has 5 column then 2nd row can
have any no of column for the given table
SQL queries are used JSON, BSON format
6
8. Advantages
Schema less
Structure of single object is clear
No complex joins
Document-based Query language
Conversion/Mapping is not needed
Use internal memory, hence faster
8
9. Why and Where to use
Object oriented storage style (JSON)
Index on any attributes
Replication and Availability
Auto-sharding
Big data
Content management system
Mobile and social infrastructure
Data Hub
9
10. Terminology Translation 10
SQL Terms/Concepts MongoDB Terms/Concepts
Database Database
Table Collection
Row Document or BSON document
Column Field
Index Index
Table joins Embedded documents & linking
Unique column or column combination as
primary key.
Primary key is automatically set to the
_id field.
Aggregation (e.g. group by) Aggregation pipeline
11. CRUD Operations
Insertion:
Update:
Delete:
11
SQL MongoDB Command
INSERT INTO t (fn, ln) VALUES (‘Saroj',
‘Shakya') db.t.insert({fn:‘Saroj', ln: ‘Shakya'})
SQL MongoDB Command
UPDATE t SET ln='Nepal' WHERE
ln='Shakya' db.t.update({ln:‘Shakya'},{$set:{ln:‘Nepal'}})
SQL MongoDB Command
DELETE FROM t WHERE fn=‘Saroj' db.t.remove({fn:‘Saroj'})
12. Retrieving Data 12
SQL Statement MongoDB Commands
SELECT *
FROM table
db.collection.find()
SELECT *
FROM table
WHERE artist = ‘Rekha’
db.collection.find({Artist:”Rekha”})
SELECT*
FROM table
ORDER BY Title
db.collection.find().sort(Title:1)
DISTINCT .distinct()
GROUP BY .group()
>=, < $gte, $lt
16. Conclusions
MongoDB is fast
Very little CPU overhead
Implemented in C++ for best performance
Free & Open Source, Cross-Platform, Document Oriented
Easier and faster integration of data
Very rapid development
16
10gen => MongoDB Inc.
2009
Stable Release: 8th March, 2016
High Performance: JSON Format, Less CPU Overhead, Data assessable from any Node
Scaling:
-> Cluster Scale
-> Performance Scale
-> Data Scale
Easy Assess
Provide up-to-date copy of data
Easily added extra column without affecting others
Secured Monitored, automated & integrated with our existing infrastructure
Millions ops/sec, 100 Billions Documents, Peta Bytes of Data