32
User Data Management with Please stand by... We’ll begin shortly. Audio: 1-877-668-4493 Access code: 666 500 606 Q&A to follow the webinar Recording Available 24 Hours After Event Other issues? E-mail [email protected] Kevin Hanson Solutions Architect, 10gen [email protected] twitter: @hungarianhc

Webinar: User Data Management with MongoDB

  • Upload
    mongodb

  • View
    3.100

  • Download
    2

Embed Size (px)

DESCRIPTION

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.

Citation preview

Page 1: Webinar: User Data Management with MongoDB

User Data Managementwith

Please stand by...We’ll begin shortly.

Audio: 1-877-668-4493Access code: 666 500 606

Q&A to follow the webinar

Recording Available 24 Hours After EventOther issues? E-mail [email protected]

Kevin HansonSolutions Architect, [email protected]: @hungarianhc

Page 2: Webinar: User Data Management with MongoDB

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

Page 3: Webinar: User Data Management with MongoDB

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

Page 4: Webinar: User Data Management with MongoDB

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

Page 5: Webinar: User Data Management with MongoDB

Insurance Company Data

Account Information– Name, Address, etc– Account Status– Notes

A Data Modeling

Exercise

Page 6: Webinar: User Data Management with MongoDB

Insurance Company

Page 7: Webinar: User Data Management with MongoDB

Insurance Company

Page 8: Webinar: User Data Management with MongoDB

Insurance Company

Page 9: Webinar: User Data Management with MongoDB

Insurance Company

User Opened AccountDate: 05/26/2012Status: Success

Account ModifiedDate: 06/22/2012Action: Added Spouse

User Call LogDate: 07/24/2012Type: Complaint

Page 10: Webinar: User Data Management with MongoDB

2 Types of Data

User Opened AccountDate: 05/26/2012Status: Success

Account ModifiedDate: 06/22/2012Action: Added Spouse

User Call LogDate: 07/24/2012Type: Complaint

Page 11: Webinar: User Data Management with MongoDB

Rule of Thumb: Categories of Data Map Well to MongoDB Collections

Policies Activities

Page 12: Webinar: User Data Management with MongoDB

Policiespolicy = { name: “Kevin Hanson” employer: “10gen”, address: “555 University”, e-mail: “[email protected]”, twitter: “@hungarianhc”, spouse: “Yes”, dependents: “No”, dates: [

{start: 5/26/2012 10:12:00}, end: 5/26/2013 10:12:00}],

others: “No”}

Page 13: Webinar: User Data Management with MongoDB

Activities

activity = { user-id: “kevinhanson421” type: “account-opening”, status: “Success”, dates: 5/26/2012 10:12:00, related-doc: “/customer/kevinhanson421/open.pdf” }

User Opened AccountDate: 05/26/2012Status: Success

Account ModifiedDate: 06/22/2012Action: Added Spouse

User Call LogDate: 07/24/2012Type: Complaint

Page 14: Webinar: User Data Management with MongoDB

User Check-Ins

Activity Streams– Posts, Tweets, Check-Ins– Recording User Actions

Page 15: Webinar: User Data Management with MongoDB

Places

Q: Current locationA: Places near

location

User Generated Content

Places

Page 16: Webinar: User Data Management with MongoDB

Inserting a Place

var 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)

Page 17: Webinar: User Data Management with MongoDB

Updating Tips

db.places.update({name:"10gen HQ"}, {$push :{tips: {user:"Kevin", time:3/15/2012, tip:"stop by for office hours on Wednesdays from 4-6"}}}}

Page 18: Webinar: User Data Management with MongoDB

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”})

Page 19: Webinar: User Data Management with MongoDB

User Check-Ins

Places

Record User Check-Ins

Check-Ins

Users

Stats

Users

Stats

Page 20: Webinar: User Data Management with MongoDB

Usersuser1 = { name: “Kevin Hanson” e-mail: “[email protected]”, check-ins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab]}

checkins [] = ObjectId reference to Check-Ins Collection

Page 21: Webinar: User Data Management with MongoDB

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)

Page 22: Webinar: User Data Management with MongoDB

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()

Page 23: Webinar: User Data Management with MongoDB

Stats w/ MapReducemapFunc = 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!

Page 24: Webinar: User Data Management with MongoDB

Adding More User Data

User Opened AccountDate: 05/26/2012Status: Success

Account ModifiedDate: 06/22/2012Action: Added Spouse

User Call LogDate: 07/24/2012Type: Complaint

Page 25: Webinar: User Data Management with MongoDB

Adding More User Data

User Opened AccountDate: 05/26/2012Status: Success

Account ModifiedDate: 06/22/2012Action: Added Spouse

User Call LogDate: 07/24/2012Type: Complaint

Click!

Click! Click!

Click!

Click!

Page 26: Webinar: User Data Management with MongoDB

Tracking Clicks

Policies Activities

Page 27: Webinar: User Data Management with MongoDB

Each Click Creates a New Doc

Policies Activities Clicks

Page 28: Webinar: User Data Management with MongoDB

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.

Page 29: Webinar: User Data Management with MongoDB

Extending the Schemauser1 = { name: “Kevin Hanson” e-mail: “[email protected]”, check-ins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab]}

Page 30: Webinar: User Data Management with MongoDB

Extending the Schemauser1 = { name: “Kevin Hanson” e-mail: “[email protected]”, check-ins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab], friends: [7b47j62bk1d3c5621c1icv90, 1h11p62bf1d8c716za]}

Page 31: Webinar: User Data Management with MongoDB

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

Page 32: Webinar: User Data Management with MongoDB

@mongodb

conferences,  appearances,  and  meetupshttp://www.10gen.com/events

http://bit.ly/mongo>  Facebook                    |                  Twitter                  |                  LinkedIn

http://linkd.in/joinmongo

More info at http://www.mongodb.org/

[email protected]@hungarianhc