MongoDB
- walkthrough
Ran.ga.na.than B
@ran_than
A brief history
● 1960s - DBMS
● 1979 - RDBMS
● 1980s - SQL, desktop DBs, Object oriented
DBs
● 1990s - Client-Server, OLTP, OLAP
● 2000s - Web based, new SQL, NO SQL
DBs, Cloud based
Internet trend today
● Big users
● Big data
● Big cloud
Big users
Source: http://www.couchbase.com/why-nosql/nosql-database
Big Data
Sourcs: http://www.couchbase.com/why-nosql/nosql-database
“On day one of a baby’s life, the amount of data
generated is 70 times what is contained in the
Library of Congress”
Big cloud
Sourcs: http://stretch-cloud.info/wp-content/uploads/2013/11/AutoScale.jpg
The problems with RDBMS
Good at space storage at the cost of
● schema design
● data lookup and complex queries
● saving data needs coordination between
many tables
Disruption in DB - for the BIG users, data,
and the cloud
Source: http://www.mindfiresolutions.com/blog/wp-content/uploads/nosql-plm.png
NoSql DB
● Efficient data queries
● Handle large volumes of structured, and unstructured
data -- with relative ease
● Simple design
● Easy horizontal elastic scaling
● High performance because of lock free architecture
● Good bye DBAs
Primary data models
● Document model - MongoDB, CouchDB,
MarkLogic
● Graph model - Neo4j, HyperGraphDB, Allegro,
Virtuoso
● Key-Value - Redis, Dynamo, Riak, Cache, Project
Voldemort
● Column - HBase, Cassandra, Accumulo
MongoDB
“MongoDB (from humongogus) is an open-
source no sql document data store.”
Databases
● With an mongodb instance, there can be
many databases (high-level containers)
● each database can have zero or more
collections
Collections
● Containers for documents that share one or
more indexes
● Equivalent of RDBMS table
● No schema and can have different fields
● Exists within a single DB
● Contains zero or more documents
Document
● Designed with notion of “Document”. Some
standard encoding like: XML, JSON, BSON,
YAML, other binary formats (pdf, word, excel, etc)
● Document is kind of record, limited to 16 MB
size
● Contains one or more fields (kind of
columns, since fields are document level)
Recap
● MongoDB is made up of databases which contain
collections.
● A collection is made up of documents.
● Each document is made up of fields.
● Collections can be indexed, which improves lookup and
sorting performance.
● When we get data from MongoDB we do so through a
cursor whose actual execution is delayed until
necessary
RDBMS equivalent
RDBMS MongoDB
Database Database
Table/View Collection
Row/Record JSON Document stored as BSON
Index Index
Join Embedded Document
Foreign Key Reference
Partition Shard
MongoDB stores in BSON
Simple JSON data (stored in BSON):
{
"id": 1,
"jsonrpc": "2.0",
"method": "subtract",
"params": [42, 23]
}
With embedded data - easy to query
Installation and Setup
1. Download from http://www.mongodb.org/downloads
2. Create a data directory, where you want the
data to be stored: mkdir data
3. Start mongodb server:
<installed path>/bin/mongod --dbpath=data
4. Access http://localhost:28017 (if mongod
running with default port on the local machine)
MongoDB shell
Start <installed dir>/bin/mongo
Save and retrieve using terminal
Replication
Sharding
Some topics to discuss
● Joins
● Capped collection
● Durability/Journaling
● Indexes
● Sharding
● Replication
● Backup and Restore
Use right tool
Thank you
Ran.ga.na.than B
https://twitter.com/ran_than

Mongo db