A Brief MongoDB Intro

Post on 10-May-2015

1.838 views 0 download

Tags:

description

A brief mongodb intro

Transcript of A Brief MongoDB Intro

MongoDB

The Highly Scalable, Enterprise Grade, Open Source Database

NoSQL: A New Era of Databases

•Big Data, Big Problem

Scaling for the Demands of Modern Applications

Starting from Scratch

•10gen as an open source ‘app engine’ cloud platform•Backend storage needs

•Agility

•Scalability

•Feature-richness

•Performance

•Ease of use

Agility

•MongoDB is document-oriented. •JSON-like objects•‘Documents’ are organized into ‘Collections’•Schema is not enforced

> a = { name: “mongo” }; { “name” : “mongo”}>b = { x : 3 }; { “x ” : 3 }> c = { x : 4 , j : 1 }; { “x ” : 4 , “j” : 1 }>db.things.save(a)>db.things.save(b)>db.things.save(c)>db.things.find(){ "_id" : ObjectId("4c2209f9f3924d31102bd84a"), "name" : "mongo" }{ "_id" : ObjectId("4c2209fef3924d31102bd84b"), "x" : 3 }{ "_id" : ObjectId("4c220a42f3924d31102bd856"), "x" : 4, "j" : 1 }

Deep Data

{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : ”roger", date : "Sat Jul 24 2010 19:47:11 GMT-0700 (PDT)", text : "I love J.Biebs...", tags : [ ”rockstar", ”puppy-love" ], comments_count: 1, comments : [

{author : ”Gretchen",date : "Sat Jul 24 2010 20:51:03 GMT-0700 (PDT)",text : ” Biebs is Toll!!!!"

} ]}

Replication•Replication for high availability

•Replica Sets

•Auto-failover

•Primary fails, secondary elected primary

•Primary repaired, becomes secondary

•Single-write node

•Great for higher read volume

Replication

PrimaryPrimary

SecondarySecondarySecondarySecondary

SecondarySecondary SecondarySecondary

ClieClientnt

Scalability

•MongoDB features autosharding for horizontal scalability

mongodmongod mongodmongodmongodmongod

mongosmongosmongodmongod

mongodmongod

mongodmongod

Config Servers

Shard Shard Shard

ClienClientt

Sharding with Replica Sets

mongodmongod

mongosmongosmongodmongod

mongodmongod

mongodmongod

Config Servers

Shard Shard Shard

mongomongodd

mongomongodd

mongodmongod

mongomongodd

mongomongodd

mongodmongod

mongomongodd

mongomongodd

ClienClientt

Performance

•Data Model

•Dynamic

•Deep data•In-place updates•Simplicity

Performance•milancermak.posterous.com

Performance

•MongoDB test results:

•siege -f ./stress_urls.txt -c 300 -r

10 -d1 -i

•Transactions: 2994 hits

•Availability: 99.80 %

•Elapsed time: 11.95 secs

•Data transferred: 3.19 MB

•Response time: 0.26 secs

•Transaction rate: 250.54 trans/sec

•Throughput: 0.27 MB/sec

•Concurrency: 65.03

•Successful transactions: 2994

•Failed transactions: 6

•Longest transaction: 1.47

•Shortest transaction: 0.00

MySQL test results:

siege -f ./stress_urls_mysql.txt -c 300 -r 10 -

d1 -i

Transactions: 2832 hits

Availability: 94.40 %

Elapsed time: 23.53 secs

Data transferred: 2.59 MB

Response time: 0.74 secs

Transaction rate: 120.36 trans/sec

Throughput: 0.11 MB/sec

Concurrency: 89.43

Successful transactions: 2832

Failed transactions: 168

Longest transaction: 16.36

Shortest transaction: 0.00

obvioushints.blogspot.com

Performance•bcbio.wordpress.com

Recent MongoDB Conferences

MongoDB Downloads

Production + Deployments

Thank you

@mongodb

scott@10gen.com; adam@10gen.comMongo France, March 23

MongoSF, May 24http://www.10gen.com/events

http://bit.ly/mongofb Facebook | Twitter | LinkedIn http://linkd.in/joinmongo

download at mongodb.org

(SQL vs MongoDB)•SQL Statement •Mongo Query Language Statement •CREATE TABLE USERS (a Number, b Number)•implicit; can be done explicitly•INSERT INTO USERS VALUES(1,1)•db.users.insert({a:1,b:1})•SELECT a,b FROM users•db.users.find({}, {a:1,b:1})•SELECT * FROM users•db.users.find()•SELECT * FROM users WHERE age=33•db.users.find({age:33})•SELECT a,b FROM users WHERE age=33•db.users.find({age:33}, {a:1,b:1})•SELECT * FROM users WHERE age=33 ORDER BY name•db.users.find({age:33}).sort({name:1})•SELECT * FROM users WHERE age>33•db.users.find({'age':{$gt:33}})})•SELECT * FROM users WHERE age<33•db.users.find({'age':{$lt:33}})})•SELECT * FROM users WHERE name LIKE "%Joe%"•db.users.find({name:/Joe/})•SELECT * FROM users WHERE name LIKE "Joe%"•db.users.find({name:/^Joe/})

CREATE INDEX myindexname ON users(name,ts DESC)db.users.ensureIndex({name:1,ts:-1})SELECT * FROM users WHERE a=1 and b='q'db.users.find({a:1,b:'q'})SELECT * FROM users LIMIT 10 SKIP 20db.users.find().limit(10).skip(20)SELECT * FROM users WHERE a=1 or b=2db.users.find( { $or : [ { a : 1 } , { b : 2 } ] } )SELECT * FROM users LIMIT 1db.users.findOne()EXPLAIN SELECT * FROM users WHERE z=3db.users.find({z:3}).explain()SELECT DISTINCT last_name FROM usersdb.users.distinct('last_name')SELECT COUNT(*y)FROM usersdb.users.count()SELECT COUNT(*y)FROM users where AGE > 30db.users.find({age: {'$gt': 30}}).count()