SlideShare a Scribd company logo
Solutions Architect, MongoDB
Heather Kirksey
#MongoDB
User Data Management
with MongoDB
Agenda
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
MongoDB is a(n) ___________
database
• Document
• Open source
• High performance
• Horizontally scalable
• Full featured
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
Data Modeling Exercise
• Insurance Company Data
• Account information
– Name, address, etc
– Account status
– Notes
Data Modeling Example
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
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
Rule of Thumb
• Categories of data map well to MongoDB
Collections
Policies Activities
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}],
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
User Check-Ins
• Activity Streams
– Posts, tweets, check-ins
– Recording user actions
Places
Q: Current location
A: Places near location
User Generated
Content
Places
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)
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”}}})
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”})
User Check Ins
Record User Check-Ins
Check-Ins
Users
Stats
Users
Stats
Users
user1 = {
name: “John Smith”
e-mail: “me@john.smith.com”,
check-ins: [4b97e62bf1d8c7152c9ccb74,
5a20e62bf1d8c736ab]
}
checkins [] = ObjectId reference to Check-Ins
Collection
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)
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()
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!
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
Tracking Clicks
Policies Activities
Each Click Creates a New Doc
Policies Activities Clicks
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.
Extending the Schema
user1 = {
name: “John Smith”
e-mail: “me@John.Smith.com”,
check-ins:
[4b97e62bf1d8c7152c9ccb74,
5a20e62bf1d8c736ab]
}
Extending the Schema
user1 = {
name: “John Smith”
e-mail: “me@John.Smith.com”,
check-ins:
[4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d
8c736ab]
}
friends:
[7b47j62bk1d3c5621c1icv90, 1h11p62bf1d8
c716za]
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
Questions?
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
Solutions Architect, MongoDB
Heather Kirksey
#MongoDB
Thank You

More Related Content

PPTX
Webinar: Back to Basics: Thinking in Documents
PPTX
MongoDB Schema Design: Practical Applications and Implications
PDF
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
PDF
Mongo DB schema design patterns
PPT
MongoDB Schema Design
PPTX
Webinar: Schema Design
PDF
1 24 - user data management
PPTX
MongoDB Schema Design: Four Real-World Examples
Webinar: Back to Basics: Thinking in Documents
MongoDB Schema Design: Practical Applications and Implications
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
Mongo DB schema design patterns
MongoDB Schema Design
Webinar: Schema Design
1 24 - user data management
MongoDB Schema Design: Four Real-World Examples

What's hot (20)

PDF
Learn Learn how to build your mobile back-end with MongoDB
PDF
Webinar: Building Your First App with MongoDB and Java
PPT
5 Pitfalls to Avoid with MongoDB
PDF
MongoDB Schema Design
PPTX
Back to Basics 1: Thinking in documents
PDF
Building your first app with mongo db
PPTX
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
PDF
MongoDB and Schema Design
PPTX
MongoDB for Developers
KEY
Schema Design by Example ~ MongoSF 2012
PDF
MongoDB Launchpad 2016: What’s New in the 3.4 Server
PPTX
Webinar: Best Practices for Getting Started with MongoDB
PPTX
Indexing Strategies to Help You Scale
PPTX
Dev Jumpstart: Schema Design Best Practices
PDF
Building your first app with MongoDB
PPTX
Database Trends for Modern Applications: Why the Database You Choose Matters
PPTX
Back to Basics Webinar 2: Your First MongoDB Application
PPTX
Back to Basics: My First MongoDB Application
PPTX
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
PDF
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
Learn Learn how to build your mobile back-end with MongoDB
Webinar: Building Your First App with MongoDB and Java
5 Pitfalls to Avoid with MongoDB
MongoDB Schema Design
Back to Basics 1: Thinking in documents
Building your first app with mongo db
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
MongoDB and Schema Design
MongoDB for Developers
Schema Design by Example ~ MongoSF 2012
MongoDB Launchpad 2016: What’s New in the 3.4 Server
Webinar: Best Practices for Getting Started with MongoDB
Indexing Strategies to Help You Scale
Dev Jumpstart: Schema Design Best Practices
Building your first app with MongoDB
Database Trends for Modern Applications: Why the Database You Choose Matters
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics: My First MongoDB Application
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
Ad

Similar to User Data Management with MongoDB (20)

PDF
Webinar: User Data Management with MongoDB
PPTX
Creating a Single View: Overview and Analysis
PPTX
Systems of engagement
PPTX
Powering Systems of Engagement
PDF
Data_Modeling_MongoDB.pdf
PPTX
Creating a Single View Part 1: Overview and Data Analysis
PPTX
Webinar: Building Your First Application with MongoDB
PPTX
Advanced Document Modeling Techniques from a High-Scale Commerce Platform
PPTX
Webinar: How Financial Firms Create a Single Customer View with MongoDB
KEY
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
KEY
Building Your First MongoDB Application
PPTX
Socialite, the Open Source Status Feed
PPTX
Building Your First App with MongoDB Stitch
POTX
Mobile 1: Mobile Apps with MongoDB
PDF
New Metadata Developments - Crossref LIVE South Africa
POTX
1140 p2 p04_and_1350_p2p05_and_1440_p2p06
PPTX
Redis data modeling examples
PPTX
[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch
PDF
Single View of the Customer
PPT
Building web applications with mongo db presentation
Webinar: User Data Management with MongoDB
Creating a Single View: Overview and Analysis
Systems of engagement
Powering Systems of Engagement
Data_Modeling_MongoDB.pdf
Creating a Single View Part 1: Overview and Data Analysis
Webinar: Building Your First Application with MongoDB
Advanced Document Modeling Techniques from a High-Scale Commerce Platform
Webinar: How Financial Firms Create a Single Customer View with MongoDB
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Building Your First MongoDB Application
Socialite, the Open Source Status Feed
Building Your First App with MongoDB Stitch
Mobile 1: Mobile Apps with MongoDB
New Metadata Developments - Crossref LIVE South Africa
1140 p2 p04_and_1350_p2p05_and_1440_p2p06
Redis data modeling examples
[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch
Single View of the Customer
Building web applications with mongo db presentation
Ad

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Machine learning based COVID-19 study performance prediction
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Cloud computing and distributed systems.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Big Data Technologies - Introduction.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
cuic standard and advanced reporting.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Programs and apps: productivity, graphics, security and other tools
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Weekly Chronicles - August'25 Week I
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
Dropbox Q2 2025 Financial Results & Investor Presentation
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.
sap open course for s4hana steps from ECC to s4
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Cloud computing and distributed systems.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
MIND Revenue Release Quarter 2 2025 Press Release
Big Data Technologies - Introduction.pptx
The AUB Centre for AI in Media Proposal.docx
cuic standard and advanced reporting.pdf
MYSQL Presentation for SQL database connectivity
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Programs and apps: productivity, graphics, security and other tools

User Data Management with MongoDB

  • 1. Solutions Architect, MongoDB Heather Kirksey #MongoDB User Data Management with MongoDB
  • 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. MongoDB is a(n) ___________ database • Document • Open source • High performance • Horizontally scalable • Full featured
  • 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. Data Modeling Exercise • Insurance Company Data • Account information – Name, address, etc – Account status – Notes
  • 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. 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. Rule of Thumb • Categories of data map well to MongoDB Collections Policies Activities
  • 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. 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. User Check-Ins • Activity Streams – Posts, tweets, check-ins – Recording user actions
  • 14. Places Q: Current location A: Places near location User Generated Content Places
  • 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. 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. 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. User Check Ins Record User Check-Ins Check-Ins Users Stats Users Stats
  • 19. Users user1 = { name: “John Smith” e-mail: “me@john.smith.com”, check-ins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab] } checkins [] = ObjectId reference to Check-Ins Collection
  • 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. 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. 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. 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
  • 25. Each Click Creates a New Doc Policies Activities Clicks
  • 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. Extending the Schema user1 = { name: “John Smith” e-mail: “me@John.Smith.com”, check-ins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab] }
  • 28. Extending the Schema user1 = { name: “John Smith” e-mail: “me@John.Smith.com”, check-ins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d 8c736ab] } friends: [7b47j62bk1d3c5621c1icv90, 1h11p62bf1d8 c716za]
  • 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
  • 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. Solutions Architect, MongoDB Heather Kirksey #MongoDB Thank You