Building your first application w/mongoDB MongoSV2011
Upcoming SlideShare
Loading in...5
×
 

Building your first application w/mongoDB MongoSV2011

on

  • 3,311 views

This talk will introduce the features of MongoDB by walking through how one can building a simple location-based application using MongoDB. The talk will cover the basics of MongoDB's document model, ...

This talk will introduce the features of MongoDB by walking through how one can building a simple location-based application using MongoDB. The talk will cover the basics of MongoDB's document model, query language, map-reduce framework and deployment architecture.

Statistics

Views

Total Views
3,311
Views on SlideShare
2,745
Embed Views
566

Actions

Likes
6
Downloads
78
Comments
0

5 Embeds 566

http://spf13.com 502
http://feeds.feedburner.com 37
http://localhost 18
http://www.newsblur.com 5
http://www.linkedin.com 4

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Memory mapped files, BSON, indexes, multiple data types, binary files, etc\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Memory mapped files, BSON, indexes, multiple data types, binary files, etc\n
  • \n
  • \n
  • Memory mapped files, BSON, indexes, multiple data types, binary files, etc\n
  • \n
  • \n
  • \n
  • \n
  • Memory mapped files, BSON, indexes, multiple data types, binary files, etc\n
  • \n
  • \n
  • Memory mapped files, BSON, indexes, multiple data types, binary files, etc\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Building your first application w/mongoDB MongoSV2011 Building your first application w/mongoDB MongoSV2011 Presentation Transcript

  • Building Applications With MongoDB An Introduction With Steve Francia@spf13
  • Agenda•MongoDB: Data modeling, queries, geospatial, updates, map reduce•Using a location-based app as an example•Example Works in MongoDB JS shell
  • Why MongoDB• Open source• Designed for today • Today’s hardware / environments • Today’s challenges• Great developer experience• Reliable• Scalable
  • Use Cases • RDBMS replacement for high-traffic web applications • Content Management-type applications • Real-time analytics • High-speed data loggingWeb 2.0, Media, SaaS, Gaming, Finance, Telecom, Healthcare
  • In Good Company
  • Let’s Design An App• Users Check-in to a Location• Leave Notes and Comments About That Location• Requirements, then Documents
  • Terminology RDBMS MongoDBTable, View ➜ CollectionRow ➜ JSON DocumentIndex ➜ IndexJoin ➜ Embedded DocumentPartition ➜ ShardPartition Key ➜ Shard Key
  • Documents{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "spf13", date : "Sat Jul 24 2010 19:47:11", text : "MongoSF", tags : [ "San Francisco", "MongoDB" ]} Note: _id is unique, but can be anythingyou’d like
  • CollectionsDoc 1 Doc 4 Doc 7Doc 2 Doc 5 Doc 8Doc 3 Doc 6 Doc 9Places Users Check-Ins
  • Application Goals (1) Q: Current location (3) Record user A: Places near location checkins(2) Add user (4) Stats aboutgenerated checkinscontent Places Check ins
  • Places v1place1 = { name : "10gen HQ", address : "134 5th Avenue 3rd Floor", city : "New York", zip : "10011"}
  • Places v2place1 = { name : "10gen HQ", address : "134 5th Avenue 3rd Floor", city : "New York", zip : "10011"}> db.posts.find({zip: "10011"}).limit(10)
  • Places v2place1 = { name : "10gen HQ", address : "134 5th Avenue 3rd Floor", city : "New York", zip : "10011", tags : [ "business", "awesome" ]}
  • Places v3place1 = { name : "10gen HQ", address : "134 5th Avenue 3rd Floor", city : "New York", zip : "10011", tags : [ "business", "awesome" ]}> db.posts.findOne({ zip: "10011", tags: "awesome" })
  • Places v3place1 = { name : "10gen HQ", address : "134 5th Avenue 3rd Floor", city : "New York", zip : "10011", tags : [ "business", "awesome" ], latlong : [40.0,72.0]}
  • Places v3place1 = { name : "10gen HQ", address : "134 5th Avenue 3rd Floor", city : "New York", zip : "10011", tags : [ "business", "awesome" ], latlong : [40.0,72.0]}> db.places.ensureIndex({latlong : "2d"})
  • Places v3place1 = { name : "10gen HQ", address : "134 5th Avenue 3rd Floor", city : "New York", zip : "10011", tags : [ "business", "awesome" ], latlong : [40.0,72.0]}> db.places.ensureIndex({latlong : "2d"})> db.places.find({latlong:{$near:[40,70]}})
  • Places v4place1 = { name : "10gen HQ", address : "134 5th Avenue 3rd Floor", city : "New York", zip : "10011", tags : [ "business", "awesome" ], latlong : [40.0,72.0], tips : [ { user : "ryan", time : 6/26/2010, tip : "stop by for office hours onWednesdays from 4-6pm"}, {.....}]}
  • Inserting PlacesInitial Data Load> db.places.insert(place1)
  • Querying Your Place Creating Your Index> db.places.ensureIndex({latlong : "2d"})> db.places.ensureIndex({ tags : 1 })> db.places.ensureIndex({ name : 1 })
  • Querying PlacesFinding Places > db.places.find({latlong:{$near:[40,70]}})With Regular Expressions > db.places.find({name: /^typeAheadString/ })By Tag > db.posts.find({tags: "business" })
  • Application Goals (1) Q: Current location (3) Record user A: Places near location checkins(2) Add user (4) Stats aboutgenerated checkinscontent Places Check ins
  • Updating PlacesUsing Update to Add Tips> db.places.update({name:"10gen HQ"},{ $push : {tips: {user:"nosh", time:6/26/2010, tip:"stop by for office hours onWednesdays from 4-6"}}}})
  • Atomic Updates• $set, $unset, $rename• $push, $pop, $pull, $addToSet• $inc
  • Application Goals (1) Q: Current location (3) Record user A: Places near location checkins(2) Add user (4) Stats aboutgenerated checkinscontent Places Check ins
  • Users user1 = { name : "ben", address : "ben@email.com", ... checkins : [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab] }checkins [] = ObjectId reference to check-incollection
  • Check-Inscheckin1 = { place : "10gen HQ", ts : 9/20/2010 10:12:00, userId : <objectId of user>}
  • Checking In 2 Operations• Insert check in object [checkin collection]• Update ($push) user object [user collection]
  • Querying Your PlaceCreating Your Index> db.checkins.ensureIndex({place:1,ts:1})> db.checkins.ensureIndex({ ts:1 })
  • Application Goals (1) Q: Current location (3) Record user A: Places near location checkins(2) Add user (4) Stats aboutgenerated checkinscontent Places Check ins
  • Simple Stats> db.checkins.find({place : "10gen HQ"})> db.checkins.find({place : "10genHQ"}).sort({ts:-1}).limit(10)> db.checkins.find({place : "10gen HQ", ts:{ $gt: <midnight>}}).limit()> db.checkins.find().sort({ts:-1}).limit(50)
  • Stats With MapReducemapFunc = function() { emit(this.place, 1); }reduceFunc = function(key, values) { return Array.sum(values);}db.checkins.mapReduce(mapFunc,reduceFunc, { query:{ timestamp: {$gt:<nowminus3hrs>}}, out: result })result = [{_id:”10gen HQ”, value: 17}, {…..}, {….}]db.result.find({ value: {$gt: 15}, _id: {$in: [….., ….., …..]} })
  • Application Goals (1) Q: Current location (3) Record user(2) Add usergeneratedcontent :)A: Places near location checkins (4) Stats about checkins Places Check ins
  • MongoDBDeployments
  • Replica SetsPrimary Primary PrimarySecondary Secondary SecondarySecondary Arbiter Secondary Secondary Secondary
  • Sharding App App App Server Server Server MongoS MongoS MongoS ConfigD ConfigD ConfigDMongoD MongoD MongoD MongoDMongoD MongoD MongoD MongoDMongoD MongoD MongoD MongoD
  • Try it for yourself at try.mongodb.org
  • spf13.com github.com/spf13 @spf13 Questions? download at mongodb.orgWe’re hiring!! Engineers, Sales, Evangelist, Marketing & Support Contact us at jobs@10gen.com