Webinar: User Data Management with MongoDB

3,377 views
3,256 views

Published on

Storing data about users is central to most applications. Whether you run a social network, an identity management system, or an online game, your users are the core of your business. In this webinar, we will discuss MongoDB’s capability to accommodate your evolving user data model and sustain the transaction load associated with accessing and updating user data.

Published in: Technology
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,377
On SlideShare
0
From Embeds
0
Number of Embeds
1,789
Actions
Shares
0
Downloads
39
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide

Webinar: User Data Management with MongoDB

  1. 1. User Data Management with Please stand by... We’ll begin shortly. Audio: 1-877-668-4493Kevin HansonSolutions Architect, 10gen Access code: 666 500 606kevin@10gen.com Q&A to follow the webinartwitter: @hungarianhc Recording Available 24 Hours After Event Other issues? E-mail webinars@10gen.com
  2. 2. Agenda// High Level Overview> MongoDB> User Data// Modeling & Querying User Data> Insurance Company User Data> User Check-Ins// Extending the Data Model for Future Use-Cases> Tracking User Activity> Social Media
  3. 3. 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 – Easy for Administrators to Scale• More Features at http://www.mongodb.org/• Overview Video: http://www.10gen.com/what-is-mongodb
  4. 4. User Data• Account Information – Name, Address, etc – Account Status – Notes• Activity Streams – Posts, Tweets, Likes, Check-Ins – Recording User Actions• Social Networks – Friends, Connections – Groups, Tags
  5. 5. Insurance Company DataAccount Information – Name, Address, etc – Account Status eling – Notes Mod A Data rcise Exe
  6. 6. Insurance Company
  7. 7. Insurance Company
  8. 8. Insurance Company
  9. 9. Insurance Company User Opened Account Date: 05/26/2012 Status: Success Account Modified Date: 06/22/2012 Action: Added Spouse User Call Log Date: 07/24/2012 Type: Complaint
  10. 10. 2 Types of Data User Opened Account Date: 05/26/2012 Status: Success Account Modified Date: 06/22/2012 Action: Added Spouse User Call Log Date: 07/24/2012 Type: Complaint
  11. 11. Rule of Thumb: Categories of DataMap Well to MongoDB Collections Policies Activities
  12. 12. Policies policy = { name: “Kevin Hanson” employer: “10gen”, address: “555 University”, e-mail: “kevin@10gen.com”, twitter: “@hungarianhc”, spouse: “Yes”, dependents: “No”, dates: [ {start: 5/26/2012 10:12:00}, end: 5/26/2013 10:12:00}], others: “No” }
  13. 13. Activities User Opened AccountDate: 05/26/2012 activity = {Status: Success user-id: “kevinhanson421” type: “account-opening”, Account ModifiedDate: 06/22/2012 status: “Success”,Action: Added Spouse dates: 5/26/2012 10:12:00, related-doc: “/customer/ User Call Log kevinhanson421/open.pdf”Date: 07/24/2012 }Type: Complaint
  14. 14. User Check-InsActivity Streams – Posts, Tweets, Check-Ins – Recording User Actions
  15. 15. Places Q: Current location A: Places near locationUser Generated Content Places
  16. 16. Inserting a Placevar p = { name: “10gen HQ”, address: “578 Broadway, 7th Floor”, city: “New York”, zip: “10012”, tags: [“mongoDB”, “business”], latlong: [40.0, 72.0], tips: [{user: “kevin”, time: “3/15/2012”,tip:“Make sure to stop by for office hours!”}]}> db.posts.save(p)
  17. 17. Updating Tipsdb.places.update({name:"10gen HQ"}, {$push :{tips: {user:"Kevin", time:3/15/2012, tip:"stop by for office hours on Wednesdays from 4-6"}}}}
  18. 18. Querying Our Places• Creating 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]}})• Regular Expressions ★ db.places.find({name: /^typeaheadstring/)• Using Tags ★ db.places.find({tags: “business”})
  19. 19. User Check-InsRecord User Check-Ins Users Stats Stats Check-Ins Users
  20. 20. Usersuser1 = { name: “Kevin Hanson” e-mail: “kevin@10gen.com”, check-ins: [4b97e62bf1d8c7152c9ccb74,5a20e62bf1d8c736ab]}checkins [] = ObjectId reference to Check-InsCollection
  21. 21. Check-Insuser1 = { place: “10gen HQ”, ts: 9/20/2010 10:12:00, userId: <object id of user>}Every Check-In is Two Operations• Insert a Check-In Object (check-ins collection)• Update ($push) user object with check-in ID(users collection)
  22. 22. Simple Statsdb.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()
  23. 23. Stats w/ 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}, ….., ….]... or try using the new aggregation framework!
  24. 24. Adding More User Data User Opened Account Date: 05/26/2012 Status: Success Account Modified Date: 06/22/2012 Action: Added Spouse User Call Log Date: 07/24/2012 Type: Complaint
  25. 25. Adding More User Data Click! Click! User Opened Account Date: 05/26/2012 Click! Status: Success Account Modified Click! Date: 06/22/2012 Click! Action: Added Spouse User Call Log Date: 07/24/2012 Type: Complaint
  26. 26. Tracking ClicksPolicies Activities
  27. 27. Each Click Creates a New DocPolicies Activities Clicks
  28. 28. Clicksclick = { user: “kevinhanson”, ts: 9/20/2010 10:12:00, link: “http://some-link-here.com/wherever”}Now we can audit user activity...db.clicks.find({user:”kevinhanson”}).sort({ts:-1})Show me all of Kevin’s clicks sorted by timestamp.
  29. 29. Extending the Schemauser1 = { name: “Kevin Hanson” e-mail: “kevin@10gen.com”, check-ins: [4b97e62bf1d8c7152c9ccb74,5a20e62bf1d8c736ab]}
  30. 30. Extending the Schemauser1 = { name: “Kevin Hanson” e-mail: “kevin@10gen.com”, check-ins: [4b97e62bf1d8c7152c9ccb74,5a20e62bf1d8c736ab], friends: [7b47j62bk1d3c5621c1icv90,1h11p62bf1d8c716za]}
  31. 31. Takeaways// User Data Fits Well in MongoDB> Flexible Data Model> Stay Agile; Make Changes> Many Customers in Production// Application Patterns Drive Data Design> Optimize Data Model For Queries> Primary Use Cases Drive Design// Adding Features Can Be Easy> Create New Data Structures> Extend Existing
  32. 32. More info at http://www.mongodb.org/ conferences,  appearances,  and  meetups http://www.10gen.com/events Questions? kevin@10gen.com @hungarianhc Facebook                    |                  Twitter                  |                  LinkedInhttp://bit.ly/mongo>   @mongodb http://linkd.in/joinmongo

×