mongodb at the silicon valley iphone and ipad developers' meetup
DESCRIPTION
Aaron Staple's presentation at the Silicon Valley iPhone and iPad Developers' Meetup on July 19: http://www.meetup.com/sviphone/calendar/13248809/TRANSCRIPT
Version 1.6comes out in 2 weeks
Production Examples
RDBMSRDBMS(Oracle, MySQL)(Oracle, MySQL)
New Gen. New Gen. OLAPOLAP
(vertica, aster, (vertica, aster, greenplum)greenplum)
Non-Non-relationalrelational
Operational Operational StoresStores(“NoSQL”)(“NoSQL”)
non-relational, next-generation operational datastores and databases
NoSQL Really Means:
Horizontally Scalable
Architectures
no joins
no complex transactions+
New Data Models
no joins
no complex transactions+
New Data Modelsmore natural ways to develop
applications?
JSON-style Documents
{“hello”: “world”}
\x16\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x00
http://bsonspec.org
represented as BSON
Flexible “Schemas”
{“author”: “mike”, “links”: 3, “date”: "Sun Jul 18 2010 14:40:20 GMT-0700 (PDT)" “text”: “...”}
Flexible “Schemas”
{“author”: “eliot”, “date”: "Sun Jul 18 2010 14:40:22 GMT-0700 (PDT)" “text”: “...”, “tags”: [“mongodb”]}
Dynamic Queries
Posts by Author
db.posts.find({author: “mike”})
Last 10 Posts
db.posts.find() .sort({date: -1}) .limit(10)
Posts Since April 1
april_1 = new Date(2010, 3, 1)db.posts.find({date: {$gt: april_1}})
Index any combination of fields, including embedded fields
Indexes{“author”: “mike”, “links”: 3, “date”: "Sun Jul 18 2010 14:40:20 GMT-0700 (PDT)" “text”: “...”}
db.posts.ensureIndex({links: 1})
Indexes{author: “mike”, …, comments: [ {author: “eliot”, date: new Date(), text: “great post!”} }, … ] }
db.posts.ensureIndex({‘comments.author’: 1, ‘comments.date’: -1 })
Advanced Queries and Map/Reduce
Support
Posts Ending With ‘Tech’
db.posts.find({text: /Tech$/})
Posts With a Tagdb.posts.find({tags: “mongodb”})
...and Fastdb.posts.ensureIndex({tags: 1})
(multi-key indexes)
Variety of Operators
db.posts.find( {$or: [{a:1}, {b:{$mod:[5,2]}} ]})
Map/Reduce> m = function() { emit(this.user_id, 1); }> r = function(k,vals) { return 1; }> res = db.events.mapReduce(m, r, { query : {type:'sale'} });> db[res.result].find().limit(2){ "_id" : 8321073716060 , "value" : 1 }{ "_id" : 7921232311289 , "value" : 1 }
Atomic Updates, Unique Key Constraints
Embedding a Comment
c = {author: “eliot”, date: new Date(), text: “great post!”}
db.posts.update({_id: post._id}, {$push: {comments: c}})
Many Supported Platforms / Languages
with Native Drivers
Focus on Performance
Focus on performance
depth of functionality
scala
bil
ity
& p
erf
orm
an
ce •memcached•key/
value
•RDBMS
Replication and Replica Sets
master
slave slave
master
slavemaster
slavemaster
slave
I II III
Auto Sharding
client
mongos ...mongos
mon
god
...
Shards
mongod
mongod
mongod
ConfigServers
mon
god
mon
god
mon
god
mon
god
mon
god
mon
god
mon
god
mon
god
...
Auto Shardingat bit.ly
•Sharding used for bit.ly user history
•~50M users (as of late May)
•Shard on user id
•Three secondary indexes
Features you guys care about
Geospatial Indexing
db.places.ensureIndex( { loc : "2d" } )
db.places.find( { loc : { $near :[50,50] } } ).limit(20)
Geospatial Indexingdb.places.ensureIndex(
{ location : "2d" , category : 1 } );
db.places.find( { location : { $near : [50,50] }, category : 'coffee' } );
Geospatial Indexing
•Also support matching within a spatial box
•And within a a circle
Geospatial Indexing at Foursquare
•~1.3M registered users. ~615k checkins/day. Nearly 50M checkins total (as of late May). Very rapid growth.
Geospatial Indexing at Foursquare•“Who’s here” service – tracks last
3 hours for every user – uses mongo exclusively
•All checkins, tips, venues written to mongo, reads a mix of mongo / legacy postgres (as of late May)
•Migrating geo related reads to mongo first
GridFS
•Store large files by splitting them into smaller documents
•Leverages existing sharding and replication configuration
•Store metadata along with files
•Works well behind a cdn
A Note on Security•Mongo supports basic per
database authentication
•No encryption
•Not security hardened (designed to work in a safe environment behind a firewall)
•Consider ssh tunnel from app server
Wordnik Configuration•1000 requests of various types /
second
•5 billion documents (1.2TB)
•Single 2x4 core server 32gb ram, FC SAN non virtualized
•NOTE: Virtualized storage tends to perform poorly, for example if you are on EC2 you should run several EBS volumes striped
Best Use Cases
The (Mobile) Web
High Volume• User comments, voting• Real time analytics
Scaling Out• User profile, session data• Content management
Caching• Fast, in-memory caching tier
Simplify Development• No ORM or fixed schema• Easy to install and maintain
•Commercial support
•Production support, 24x7
•Consulting
•Supercharge your app development
•Training
•Learn from the experts
•10gen.com
Download MongoDBmongodb.org
let us know what you think@mongodb
get free supportgroups.google.com/group/mongodb-user
request featuresjira.mongodb.org
(grab some friends and manipulate ourvoting system )