mongo db
TRANSCRIPT
2Introduction
MongoDB = “Humongous DB”Open-source & Cross-platformDocument-based“High Performance, High Availability”Automatic Scaling
6/20/2016
3Database EvolutionFlat Files RDBMS NoSQL MongoDB1970s: 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 Store2. Tabular3. 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
6/20/2016
4Features Expressive Query Language & Secondary Indexes Strong Consistency Flexibility Scalability & Performance
6/20/2016
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 downtimeAuto-sharding built
inOperates at in-memory speed
wherever possible
6Comparisons RDBMS MongoDBRelational 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 scalingEg. 1st row has 5 column then 2nd row must have 5 column for the given table
Horizontal scalingEg. 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/20/2016
7Data FormatJSON XML{"employees“ :[{"firstName":“Anju", "lastName":“Shah"},{"firstName":“Sumit Kumar", "lastName":“Shah"},{"firstName":“Shiva K.", "lastName":“Shrestha"}]}
<employees> <employee> <firstName>Anju</firstName> <lastName>Shah</lastName> </employee> <employee> <firstName>Sumit Kumar</firstName> <lastName>Shah</lastName> </employee> <employee> <firstName>Shiva K.</firstName> <lastName>Shrestha</lastName> </employee> </employees>
6/20/2016
8Advantages 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
6/20/2016
9Why 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
6/20/2016
10Terminology Translation6/20/2016
SQL Terms/Concepts MongoDB Terms/ConceptsDatabase DatabaseTable CollectionRow Document or BSON documentColumn FieldIndex IndexTable joins Embedded documents & linkingUnique column or column combination as primary key.
Primary key is automatically set to the _id field.
Aggregation (e.g. group by) Aggregation pipeline
11CRUD OperationsInsertion:
Update:
Delete:
6/20/2016
SQL MongoDB CommandINSERT INTO t (fn, ln) VALUES (‘Saroj', ‘Shakya') db.t.insert({fn:‘Saroj', ln: ‘Shakya'})
SQL MongoDB CommandUPDATE t SET ln='Nepal' WHERE ln='Shakya'
db.t.update({ln:‘Shakya'},{$set:{ln:‘Nepal'}})
SQL MongoDB CommandDELETE FROM t WHERE fn=‘Saroj' db.t.remove({fn:‘Saroj'})
12Retrieving Data6/20/2016
SQL Statement MongoDB CommandsSELECT * FROM table
db.collection.find()
SELECT * FROM tableWHERE artist = ‘Rekha’
db.collection.find({Artist:”Rekha”})
SELECT*FROM tableORDER BY Title
db.collection.find().sort(Title:1)
DISTINCT .distinct()GROUP BY .group()>=, < $gte, $lt
16Conclusions 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
6/20/2016