Nosh Petigara [email_address] @noshinosh http://mongodb.org http://10gen.com Building applications with MongoDB – An intro...
Today’s Talk <ul><ul><li>MongoDB: Data modeling, queries, geospatial, updates, map reduce </li></ul></ul><ul><ul><li>Using...
Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Reco...
Documents doc1 = { _id:  4b97e62bf1d8c7152c9ccb74 , key1: value1, key2: value2, key3: {..., ..., ...}, key4: [..., ..., ] }
Collections doc1, doc2, doc3 Places Users Checkins doc3, doc4, doc5 doc6, doc7, doc8
Places v1 place1 = { name: &quot;10gen HQ”, address: ”134 5 th  Avenue 3 rd  Floor”, city: &quot;New York”, zip: &quot;100...
Places v2 place1 = { name: &quot;10gen HQ”, address: &quot;17 West 18th Street 8th Floor”, city: &quot;New York”, zip: &qu...
Places v3 place1 = { name: &quot;10gen HQ”, address: &quot;17 West 18th Street 8th Floor”, city: &quot;New York”, zip: &qu...
Places v4 place1 = { name: &quot;10gen HQ”, address: &quot;17 West 18th Street 8th Floor”, city: &quot;New York”, zip: &qu...
Querying your Places Creating your indexes db.places.ensureIndex({tags:1}) db.places.ensureIndex({name:1}) db.places.ensur...
Inserting and updating places Initial data load: db.places.insert(place1) Updating tips: db.places.update({name:&quot;10ge...
Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Reco...
Users user1 = { name: “nosh” email: “nosh@10gen.com”, . . . checkins: [ 4b97e62bf1d8c7152c9ccb74,  5a20e62bf1d8c736ab ] } ...
Checkins checkin1 = { place: “10gen HQ”, ts: 9/20/2010 10:12:00, userId: <objectid of user> } Check-in = 2 ops Insert chec...
Atomic Updates $set, $unset, $rename $push, $pop, $pull, $addToSet $inc
Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Reco...
Simple Stats db.checkins.find({place: “10gen HQ”) db.checkins.find({place: “10gen HQ”}) .sort({ts:-1}).limit(10) db.checki...
Stats with MapReduce mapFunc = function() { emit(this.place, 1);} reduceFunc = function(key, values) { return Array.sum(va...
Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Reco...
Single Master Deployments <ul><li>Configure as a replica set for automated failover </li></ul><ul><li>Add more secondaries...
Auto Sharded Deployment <ul><li>Autosharding distributes data among two or more replica sets </li></ul><ul><li>Mongo Confi...
Use Cases <ul><li>RDBMS replacement for high-traffic web applications </li></ul><ul><li>Content Management-type applicatio...
MongoDB in Production
Nosh Petigara [email_address] Director of Product Strategy, 10gen http://mongodb.org http://10gen.com <ul><li>We are hirin...
Upcoming SlideShare
Loading in...5
×

Building Applications with MongoDB - an Introduction

2,030

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,030
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
61
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Memory mapped files, BSON, indexes, multiple data types, binary files, etc
  • Memory mapped files, BSON, indexes, multiple data types, binary files, etc
  • Memory mapped files, BSON, indexes, multiple data types, binary files, etc
  • Memory mapped files, BSON, indexes, multiple data types, binary files, etc
  • Transcript of "Building Applications with MongoDB - an Introduction"

    1. 1. Nosh Petigara [email_address] @noshinosh http://mongodb.org http://10gen.com Building applications with MongoDB – An introduction MongoBerlin – March 25, 2011
    2. 2. Today’s Talk <ul><ul><li>MongoDB: Data modeling, queries, geospatial, updates, map reduce </li></ul></ul><ul><ul><li>Using a location-based app as an example </li></ul></ul><ul><ul><li>Example Works in MongoDB JS shell </li></ul></ul>
    3. 3. Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about checkins
    4. 4. Documents doc1 = { _id: 4b97e62bf1d8c7152c9ccb74 , key1: value1, key2: value2, key3: {..., ..., ...}, key4: [..., ..., ] }
    5. 5. Collections doc1, doc2, doc3 Places Users Checkins doc3, doc4, doc5 doc6, doc7, doc8
    6. 6. Places v1 place1 = { name: &quot;10gen HQ”, address: ”134 5 th Avenue 3 rd Floor”, city: &quot;New York”, zip: &quot;10011” } db.places.find({zip:”10011”}).limit(10)
    7. 7. Places v2 place1 = { name: &quot;10gen HQ”, address: &quot;17 West 18th Street 8th Floor”, city: &quot;New York”, zip: &quot;10011”, tags: [“business”, “recommended”] } db.places.find({zip:”10011”, tags:”business”})
    8. 8. Places v3 place1 = { name: &quot;10gen HQ”, address: &quot;17 West 18th Street 8th Floor”, city: &quot;New York”, zip: &quot;10011”, tags: [“business”, “cool place”], latlong: [40.0,72.0] } db.places.ensureIndex({latlong:”2d”}) db.places.find({latlong:{$near:[40,70]}})
    9. 9. Places v4 place1 = { name: &quot;10gen HQ”, address: &quot;17 West 18th Street 8th Floor”, city: &quot;New York”, zip: &quot;10011”, latlong: [40.0,72.0], tags: [“business”, “cool place”], tips: [ {user:&quot;nosh&quot;, time:6/26/2010, tip:&quot;stop by for office hours on Wednesdays from 4-6pm&quot;}, {.....}, {.....} ] }
    10. 10. Querying your Places Creating your indexes db.places.ensureIndex({tags:1}) db.places.ensureIndex({name:1}) db.places.ensureIndex({latlong:”2d”}) Finding places: db.places.find({latlong:{$near:[40,70]}}) With regular expressions: db.places.find({name: /^ typeaheadstring /) By tag: db.places.find({tags: “business”})
    11. 11. Inserting and updating places Initial data load: db.places.insert(place1) Updating tips: db.places.update({name:&quot;10gen HQ&quot;}, {$push :{tips: {user:&quot;nosh&quot;, time:6/26/2010, tip:&quot;stop by for office hours on Wednesdays from 4-6&quot;}}}}
    12. 12. Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about checkins
    13. 13. Users user1 = { name: “nosh” email: “nosh@10gen.com”, . . . checkins: [ 4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab ] } checkins [] = ObjectId reference to checkin collection
    14. 14. Checkins checkin1 = { place: “10gen HQ”, ts: 9/20/2010 10:12:00, userId: <objectid of user> } Check-in = 2 ops Insert check in object [checkin collection] Update ($push) user object [user collection] Indexes: db.checkins.ensureIndex({place:1, ts:1}) db.checkins.ensureIndex({ts:1})
    15. 15. Atomic Updates $set, $unset, $rename $push, $pop, $pull, $addToSet $inc
    16. 16. Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about checkins
    17. 17. Simple Stats db.checkins.find({place: “10gen HQ”) db.checkins.find({place: “10gen HQ”}) .sort({ts:-1}).limit(10) db.checkins.find({place: “10gen HQ”, ts: {$gt: midnight}}).count()
    18. 18. Stats with MapReduce mapFunc = function() { emit(this.place, 1);} reduceFunc = function(key, values) { return Array.sum(values); } res = db.checkins.mapReduce(mapFunc,reduceFunc, {query: {timestamp: {$gt:nowminus3hrs}}}) res = [{_id:”10gen HQ”, value: 17}, ….., ….] res.find({ value: {$gt: 15}, _id: {$in: [….., ….., …..]} })
    19. 19. Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about checkins
    20. 20. Single Master Deployments <ul><li>Configure as a replica set for automated failover </li></ul><ul><li>Add more secondaries to scale reads </li></ul>Primary/Master Secondary/Slave
    21. 21. Auto Sharded Deployment <ul><li>Autosharding distributes data among two or more replica sets </li></ul><ul><li>Mongo Config Server(s) handles distribution & balancing </li></ul><ul><li>Transparent to applications </li></ul>Primary/Master Secondary/Slave MongoS Mongo Config
    22. 22. Use Cases <ul><li>RDBMS replacement for high-traffic web applications </li></ul><ul><li>Content Management-type applications </li></ul><ul><li>Social, mobile </li></ul><ul><li>Real-time analytics </li></ul><ul><li>High-speed data logging </li></ul>Web 2.0, Media, SaaS, Gaming, Finance, Telecom, Healthcare
    23. 23. MongoDB in Production
    24. 24. Nosh Petigara [email_address] Director of Product Strategy, 10gen http://mongodb.org http://10gen.com <ul><li>We are hiring! </li></ul><ul><li>@mongodb </li></ul><ul><li>[email_address] </li></ul><ul><li>@noshinosh </li></ul>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×