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
![Page 2: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/2.jpg)
Version 1.6comes out in 2 weeks
![Page 3: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/3.jpg)
Production Examples
![Page 4: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/4.jpg)
RDBMSRDBMS(Oracle, MySQL)(Oracle, MySQL)
New Gen. New Gen. OLAPOLAP
(vertica, aster, (vertica, aster, greenplum)greenplum)
Non-Non-relationalrelational
Operational Operational StoresStores(“NoSQL”)(“NoSQL”)
![Page 5: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/5.jpg)
non-relational, next-generation operational datastores and databases
NoSQL Really Means:
![Page 6: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/6.jpg)
Horizontally Scalable
Architectures
no joins
no complex transactions+
![Page 7: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/7.jpg)
New Data Models
no joins
no complex transactions+
![Page 8: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/8.jpg)
New Data Modelsmore natural ways to develop
applications?
![Page 9: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/9.jpg)
JSON-style Documents
{“hello”: “world”}
\x16\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x00
http://bsonspec.org
represented as BSON
![Page 10: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/10.jpg)
Flexible “Schemas”
{“author”: “mike”, “links”: 3, “date”: "Sun Jul 18 2010 14:40:20 GMT-0700 (PDT)" “text”: “...”}
![Page 11: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/11.jpg)
Flexible “Schemas”
{“author”: “eliot”, “date”: "Sun Jul 18 2010 14:40:22 GMT-0700 (PDT)" “text”: “...”, “tags”: [“mongodb”]}
![Page 12: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/12.jpg)
Dynamic Queries
![Page 13: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/13.jpg)
Posts by Author
db.posts.find({author: “mike”})
![Page 14: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/14.jpg)
Last 10 Posts
db.posts.find() .sort({date: -1}) .limit(10)
![Page 15: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/15.jpg)
Posts Since April 1
april_1 = new Date(2010, 3, 1)db.posts.find({date: {$gt: april_1}})
![Page 16: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/16.jpg)
Index any combination of fields, including embedded fields
![Page 17: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/17.jpg)
Indexes{“author”: “mike”, “links”: 3, “date”: "Sun Jul 18 2010 14:40:20 GMT-0700 (PDT)" “text”: “...”}
db.posts.ensureIndex({links: 1})
![Page 18: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/18.jpg)
Indexes{author: “mike”, …, comments: [ {author: “eliot”, date: new Date(), text: “great post!”} }, … ] }
db.posts.ensureIndex({‘comments.author’: 1, ‘comments.date’: -1 })
![Page 19: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/19.jpg)
Advanced Queries and Map/Reduce
Support
![Page 20: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/20.jpg)
Posts Ending With ‘Tech’
db.posts.find({text: /Tech$/})
![Page 21: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/21.jpg)
Posts With a Tagdb.posts.find({tags: “mongodb”})
...and Fastdb.posts.ensureIndex({tags: 1})
(multi-key indexes)
![Page 22: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/22.jpg)
Variety of Operators
db.posts.find( {$or: [{a:1}, {b:{$mod:[5,2]}} ]})
![Page 23: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/23.jpg)
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 }
![Page 24: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/24.jpg)
Atomic Updates, Unique Key Constraints
![Page 25: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/25.jpg)
Embedding a Comment
c = {author: “eliot”, date: new Date(), text: “great post!”}
db.posts.update({_id: post._id}, {$push: {comments: c}})
![Page 26: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/26.jpg)
Many Supported Platforms / Languages
with Native Drivers
![Page 27: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/27.jpg)
Focus on Performance
![Page 28: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/28.jpg)
Focus on performance
depth of functionality
scala
bil
ity
& p
erf
orm
an
ce •memcached•key/
value
•RDBMS
![Page 29: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/29.jpg)
Replication and Replica Sets
master
slave slave
master
slavemaster
slavemaster
slave
I II III
![Page 30: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/30.jpg)
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
...
![Page 31: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/31.jpg)
Auto Shardingat bit.ly
•Sharding used for bit.ly user history
•~50M users (as of late May)
•Shard on user id
•Three secondary indexes
![Page 32: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/32.jpg)
![Page 33: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/33.jpg)
Features you guys care about
![Page 34: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/34.jpg)
Geospatial Indexing
db.places.ensureIndex( { loc : "2d" } )
db.places.find( { loc : { $near :[50,50] } } ).limit(20)
![Page 35: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/35.jpg)
Geospatial Indexingdb.places.ensureIndex(
{ location : "2d" , category : 1 } );
db.places.find( { location : { $near : [50,50] }, category : 'coffee' } );
![Page 36: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/36.jpg)
Geospatial Indexing
•Also support matching within a spatial box
•And within a a circle
![Page 37: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/37.jpg)
Geospatial Indexing at Foursquare
•~1.3M registered users. ~615k checkins/day. Nearly 50M checkins total (as of late May). Very rapid growth.
![Page 38: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/38.jpg)
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
![Page 39: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/39.jpg)
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
![Page 40: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/40.jpg)
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
![Page 41: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/41.jpg)
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
![Page 42: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/42.jpg)
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
![Page 43: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/43.jpg)
•Commercial support
•Production support, 24x7
•Consulting
•Supercharge your app development
•Training
•Learn from the experts
•10gen.com
![Page 44: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup](https://reader036.vdocuments.us/reader036/viewer/2022062513/555a699cd8b42ae7218b4d47/html5/thumbnails/44.jpg)
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 )