User Data Management with MongoDB

3,415 views

Published on

Published in: Technology
1 Comment
2 Likes
Statistics
Notes
  • I don't really get the idea in slide 28.

    what is the meaning of 'friends: [7b47j62bk1d3c5621c1icv90, 1h11p62bf1d8 c716za]'

    It's means we add new field into this user ? and his friends have ids in friends array ?
    if so, it should be like this:
    Extending the Schema user1 = { name: “John Smith” e-mail: “me@John.Smith.com”, check-ins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d 8c736ab] , friends: [7b47j62bk1d3c5621c1icv90, 1h11p62bf1d8 c716za] }
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
3,415
On SlideShare
0
From Embeds
0
Number of Embeds
899
Actions
Shares
0
Downloads
54
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

User Data Management with MongoDB

  1. 1. Solutions Architect, MongoDB Heather Kirksey #MongoDB User Data Management with MongoDB
  2. 2. Agenda
  3. 3. 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 UserActivity – Social Media
  4. 4. MongoDB is a(n) ___________ database • Document • Open source • High performance • Horizontally scalable • Full featured
  5. 5. 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
  6. 6. Data Modeling Exercise • Insurance Company Data • Account information – Name, address, etc – Account status – Notes
  7. 7. Data Modeling Example
  8. 8. Data Modeling Example User Opened Date: 05/26/2013 Status: Successful Account Modified Date: 06/04/2013 Status: Added spouse User Call Log Date: 01/22/2014 Type: Complaint
  9. 9. Insurance Company Site User Opened Date: 05/26/2013 Status: Successful Account Modified Date: 06/04/2013 Status: Added spouse User Call Log Date: 01/22/2014 Type: Complaint 2 types of data 2 types of data
  10. 10. Rule of Thumb • Categories of data map well to MongoDB Collections Policies Activities
  11. 11. Policies policy = { name: “John Smith” employer: “10gen”, address: “555 Fictional Ave”, e-mail: “me@john.smith.com”, spouse: “Yes” , dependents: “No”, dates: [ {start: 5/26/2013 10:12:00}, end: 5/26/2023 10:12:00}],
  12. 12. Activities activity = { user-id: “JohnSmith421” type: “account-opening” , status: “Success”, dates: 5/26/2013 10:12:00, related-doc: “/customer/JohnSmith421/open .pdf” } User Opened Account Date: 05/26/2013 Status: Success Account Modified Date: 06/04/2013 Action: Added Spouse User Call Log Date: 01/22/2014 Type: Complaint
  13. 13. User Check-Ins • Activity Streams – Posts, tweets, check-ins – Recording user actions
  14. 14. Places Q: Current location A: Places near location User Generated Content Places
  15. 15. Inserting a Place var p = { name: “MongoDB HQ”, address:“229 W 43rd St”, city: “NewYork”, zip: “10036”, tags: [“mongoDB”,“business”], latlong: [40.0, 72.0], tips: [{user:“John Smith”, time: “3/15/2013”,tip:“Make sure to stop by for office hours!”}]} > db.posts.save(p)
  16. 16. Updating Tips db.places.update({name: “MongoDB HQ”}, {$push :{tips: {user: “John”, time:3/10/2014, tip: “stop by for office hours on Wednesdays from 4-6”}}})
  17. 17. 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”})
  18. 18. User Check Ins Record User Check-Ins Check-Ins Users Stats Users Stats
  19. 19. Users user1 = { name: “John Smith” e-mail: “me@john.smith.com”, check-ins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab] } checkins [] = ObjectId reference to Check-Ins Collection
  20. 20. Check-Ins user1 = { place: “MongoDB 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)
  21. 21. Simple Stats db.checkins.find({place: “MongoDB HQ”) db.checkins.find({place: “MongoDB HQ”}) .sort({ts:-1}).limit(10) db.checkins.find({place: “MongoDB HQ”, ts: {$gt: midnight}}).count()
  22. 22. 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:”MongoDB HQ”, value: 17}, … , …] …or try using the aggregation framework!
  23. 23. Adding More User Data User Opened Date: 05/26/2013 Status: Successful Account Modified Date: 06/04/2013 Status: Added spouse User Call Log Date: 01/22/2014 Type: Complaint
  24. 24. Tracking Clicks Policies Activities
  25. 25. Each Click Creates a New Doc Policies Activities Clicks
  26. 26. Clicks click = { user: “JohnSmith”, ts: 9/20/2010 10:12:00, link: “http://some-link-here.com/wherever” } Now we can audit user activity... db.clicks.find({user:”JohnSmith”}).sort({ts:-1}) Show me all of John’s clicks sorted by timestamp.
  27. 27. Extending the Schema user1 = { name: “John Smith” e-mail: “me@John.Smith.com”, check-ins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab] }
  28. 28. Extending the Schema user1 = { name: “John Smith” e-mail: “me@John.Smith.com”, check-ins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d 8c736ab] } friends: [7b47j62bk1d3c5621c1icv90, 1h11p62bf1d8 c716za]
  29. 29. 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 is easy – Create new data structures – Extend existing
  30. 30. Questions?
  31. 31. MongoDB World New York City, June 23-25 #MongoDBWorld See what’s next in MongoDB including • MongoDB 2.6 • Sharding • Replication • Aggregation http://world.mongodb.com Save $200 with discount code THANKYOU
  32. 32. Solutions Architect, MongoDB Heather Kirksey #MongoDB Thank You

×