mongoDBIt’s not just about big data
08.09.2011
what is mongoDB?
“Scalable, open-source, high-performance, document-oriented database” - 10gen
Storage model
• relational– database– table– row
• mongoDB– database– collection– document / object
{ _id: 1234, author: { name: “Bob Davis”, email : [email protected] }, post: “In these troubled times I like to …“, date: { $date: “2010-07-12 13:23UTC” }, location: [ -121.2322, 42.1223222 ], rating: 2.2, comments: [ { user: “[email protected]”, upVotes: 22, downVotes: 14,
text: “Great point! I agree” }, { user: “[email protected]”, upVotes: 421, downVotes: 22,
text: “You are a moron” } ]}
Documents (a.k.a. Objects)
{ _id: 1234, author: { name: “Bob Davis”, email : [email protected] }, post: “In these troubled times I like to …“, date: { $date: “2010-07-12 13:23UTC” }, location: [ -121.2322, 42.1223222 ], rating: 2.2, comments: [ { user: “[email protected]”, upVotes: 22, downVotes: 14,
text: “Great point! I agree” }, { user: “[email protected]”, upVotes: 421, downVotes: 22,
text: “You are a moron” } ], tags: [ “Politics”, “Virginia” ]}
Flexible “Schemas”
db.posts.find({ author.name: “mike” })
dynamic queries
db.posts.find({ rating: { $gt: 2 }})
db.posts.find({ tags: “Software” })
db.posts.find().sort({date: -1}).limit(10)
query language
• Predicates– <, <=, >, >=– $all– $exists– $ne– $in– $nin– $nor– $not– $or– $and
• regular expressions
• $where (js exps)• group()• ** no joins **
db.posts.ensureIndex({ author.name : 1 }
indexes
db.posts.find({ author.name: “mike” })
geospatial indexing and queries
db.places.ensureIndex( { loc: “2d” } )
db.places.find({ loc: { $near : [50, 50] } }).limit(10)
db.places.find({loc: {$within : {$box : [[40,40],[60,60]]}}})
db.places.find({loc: {$within : {$center : [[40,40],10]}}})
Comment c = {author: “[email protected]”,
date: new Date(), text: “great post!”}
db.posts.update({_id: post._id}, {$push: {comments: c}})
atomic updates
atomic updates
• operators– $set– $unset– $inc– $push– $pushAll– $pull– $pullAll– $bit
aggregation and map/reduce
Native drivers in almost every language
• Java• Javascript• Python• Ruby• C#• PHP• and more…
Built for scalability reliability from the ground up
High performance, fault tolerant clusters made easy
•Replica sets
•Auto-sharding
But, mongoDB is not just about big data
Blog Post
"Object-Relational mapping is the Vietnam of our industry” - Ted Neward
{ _id: 1234, author: { name: “Bob Davis”, email : [email protected] }, post: “In these troubled times I like to …“, date: { $date: “2010-07-12 13:23UTC” }, location: [ -121.2322, 42.1223222 ], rating: 2.2, comments: [ { user: “[email protected]”, upVotes: 22, downVotes: 14,
text: “Great point! I agree” }, { user: “[email protected]”, upVotes: 421, downVotes: 22,
text: “You are a moron” } ], tags: [ “Politics”, “Virginia” ]}
… vs. this loveliness
mongoDB is a great general purpose database
Good uses for MongoDB
• accounts / user profiles• form data• CMS• storing geo-data• application configuration• application logging• …
Q&A
More info
• MongoDB / 10Gen– http://mongodb.org– http://10gen.com
• MongoLab– http://mongolab.com– [email protected]