Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Building Your First                      Application        Kevin Hanson  Solutions Architect, 10gen      Kevin@10gen.com ...
Step 1 - What is mongoDB??• Scalable, High-Performance, Open Source, Document-  Oriented Database   – JSON (well... BSON) ...
Step 2 - Stop Thinking Relational
Tables to Documents             {                 title: ‘MongoDB’,                 contributors: [                   { na...
ParallelsRDBMS               MongoDBTable               CollectionRow                 DocumentColumn              FieldInd...
Rich Data Model{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),  author : "roger",  date : "Sat Jul 24 2010 19:47:11 GMT-0700...
Querying>db.posts.find()  { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),    author : "roger",    date : "Sat Jul 24 2010 19...
Secondary IndexesCreate index on any Field in Document // 1 means ascending, -1 means descending >db.posts.ensureIndex({au...
Secondary Indexes// Index nested documents> db.posts.ensureIndex( “comments.author”:1 )db.posts.find({‘comments.author’:’...
Atomic Operations• $set, $unset, $inc, $push, $pushAll, $pull, $pullAll,  $bit> comment = { author: “fred”,              d...
Step 3 - Let’s Build A Sample App        Metadata Catalog                Q: Patients Matching Query                       ...
Inserting a Documentvar p = { name: “John Smith”,      address: “578 Broadway, 7th Floor”,      city: “New York”,      bir...
Let’s Add Some Information     { name: “John Smith”,     address: “578 Broadway, 7th Floor”,     city: “New York”,     bir...
Geo Tags     { name: “John Smith”,     address: “578 Broadway, 7th Floor”,     city: “New York”,     birthday: “2/15/2012”...
Doctor Notes     { name: “John Smith”,     address: “578 Broadway, 7th Floor”,     city: “New York”,     birthday: “2/15/2...
Updating Doctor Notesdb.places.update({name:”John Smith"},{$push :{notes: {doctor:”Kevin", time:3/15/2012,           note:...
Indexing / Querying Metadata// List all people whose name is “John Smith”> db.posts.ensureIndex( “name”:1 )db.posts.find(...
Demo ~ MongoDB Shell
Step 4 - Scale Your App w/       Replica Sets
Replica Sets
Replica SetsAdd Secondaries for High Availability / Read Scale High Write Load / Big Data Set -> Use mongoDB RangeBased Au...
More info at http://www.mongodb.org/          conferences, appearances, and meetups                        http://www.10ge...
Upcoming SlideShare
Loading in …5
×

Building Your First MongoDB App ~ Metadata Catalog

5,892 views

Published on

These are the slides I used for a MongoDB webinar about creating your first application with MongoDB. They start with a general MongoDB overview, continuing onto how to model data for a metadata catalog. At this point in the presentation, I break to do a live demonstration. Afterwards, I touch on scaling your application with MongoDB.

Published in: Technology, Business
  • Be the first to comment

Building Your First MongoDB App ~ Metadata Catalog

  1. 1. Building Your First Application Kevin Hanson Solutions Architect, 10gen Kevin@10gen.com @hungarianhc
  2. 2. Step 1 - What is mongoDB??• Scalable, High-Performance, Open Source, Document- Oriented Database – JSON (well... BSON) Storage Model – Indexes and Full Query Language – Easy for Developers to Pick Up• More Features at http://www.mongodb.org/• Overview Video: http://www.10gen.com/what-is-mongodb
  3. 3. Step 2 - Stop Thinking Relational
  4. 4. Tables to Documents { title: ‘MongoDB’, contributors: [ { name: ‘Eliot Horowitz’, email: ‘eliot@10gen.com’ }, { name: ‘Dwight Merriman’, email: ‘dwight@10gen.com’ } ], model: { relational: false, awesome: true } }
  5. 5. ParallelsRDBMS MongoDBTable CollectionRow DocumentColumn FieldIndex IndexJoin Embedding / LinkingSchema Object
  6. 6. Rich Data Model{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", date : "Sat Jul 24 2010 19:47:11 GMT-0700 (PDT)", text : "Spirited Away", tags : [ "Tezuka", "Manga" ], comments : [ { author : "Fred", date : "Sat Jul 24 2010 20:51:03 GMT-0700 (PDT)", text : "Best Movie Ever" } ]}
  7. 7. Querying>db.posts.find() { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", date : "Sat Jul 24 2010 19:47:11 GMT-0700 (PDT)", text : "Spirited Away", tags : [ "Tezuka", "Manga" ] }Notes: - _id is unique, but can be anything you’d like
  8. 8. Secondary IndexesCreate index on any Field in Document // 1 means ascending, -1 means descending >db.posts.ensureIndex({author: 1}) >db.posts.find({author: roger}) { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", ... }
  9. 9. Secondary Indexes// Index nested documents> db.posts.ensureIndex( “comments.author”:1 )db.posts.find({‘comments.author’:’Fred’})// Index on tags> db.posts.ensureIndex( tags: 1)> db.posts.find( { tags: ’Manga’ } )// geospatial index> db.posts.ensureIndex( “author.location”: “2d” )> db.posts.find( “author.location” : { $near : [22,42] } )
  10. 10. Atomic Operations• $set, $unset, $inc, $push, $pushAll, $pull, $pullAll, $bit> comment = { author: “fred”, date: new Date(), text: “Best Movie Ever”}> db.posts.update( { _id: “...” }, $push: {comments: comment} );
  11. 11. Step 3 - Let’s Build A Sample App Metadata Catalog Q: Patients Matching Query A: PatientsPatient Data Metadata
  12. 12. Inserting a Documentvar p = { name: “John Smith”, address: “578 Broadway, 7th Floor”, city: “New York”, birthday: “2/15/2012”}> db.patients.save(p)
  13. 13. Let’s Add Some Information { name: “John Smith”, address: “578 Broadway, 7th Floor”, city: “New York”, birthday: “2/15/2012”, clinics: [“Good Health Clinic”, “New YorkGeneral Care”]}
  14. 14. Geo Tags { name: “John Smith”, address: “578 Broadway, 7th Floor”, city: “New York”, birthday: “2/15/2012”, clinics: [“Good Health Clinic”, “New YorkGeneral Care”], latlong: [40.0, 72.0]}
  15. 15. Doctor Notes { name: “John Smith”, address: “578 Broadway, 7th Floor”, city: “New York”, birthday: “2/15/2012”, clinics: [“Good Health Clinic”, “New YorkGeneral Care”], latlong: [40.0, 72.0], notes: [{doctor:”Kevin", time:3/15/2012, note:”Patient seems healthy to me!"}]}
  16. 16. Updating Doctor Notesdb.places.update({name:”John Smith"},{$push :{notes: {doctor:”Kevin", time:3/15/2012, note:”Patient seems healthy tome!"}}}}
  17. 17. Indexing / Querying Metadata// List all people whose name is “John Smith”> db.posts.ensureIndex( “name”:1 )db.posts.find({‘name’:’John Smith’})// List all people whose name is “John Smith”, sorted bybirthday descending> db.posts.ensureIndex( name: 1, birthday: -1)> db.posts.find( { name: ’John Smith’ } ).sort({birthday: -1})// Return people that “Doctor Bob” made notes about, sortedby their name> db.posts.ensureIndex( notes.doctor: 1, name: 1)> db.posts.find( “notes.doctor”: “Doctor Bob”).sort({name:1})
  18. 18. Demo ~ MongoDB Shell
  19. 19. Step 4 - Scale Your App w/ Replica Sets
  20. 20. Replica Sets
  21. 21. Replica SetsAdd Secondaries for High Availability / Read Scale High Write Load / Big Data Set -> Use mongoDB RangeBased Auto Sharding (A Future Webinar / mongoDB Day)
  22. 22. More info at http://www.mongodb.org/ conferences, appearances, and meetups http://www.10gen.com/events Kevin Hanson kevin@10gen.com @hungarianhc Facebook | Twitter | LinkedInhttp://bit.ly/mongofb @mongodb http://linkd.in/joinmongo

×