SlideShare a Scribd company logo
http://mongodb.org http://10gen.com Building applications with MongoDB – An introduction MongoNYC – June 7, 2011  Nosh Petigara [email_address] @noshinosh
Today’s Talk MongoDB: Data modeling, queries, geospatial, updates, map reduce Using a location-based app as an example Example Works in MongoDB JS shell
Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about  checkins
Documents doc1 = { _id:  4b97e62bf1d8c7152c9ccb74 , key1: value1, key2: value2, key3: {..., ..., ...}, key4: [..., ..., ] }
Collections doc1, doc2, doc3 Places Users Checkins doc3, doc4, doc5 doc6, doc7, doc8
Places v1 place1 = { name: "10gen HQ”, address: ”134 5 th  Avenue 3 rd  Floor”, city: "New York”, zip: "10011” } db.places.find({zip:”10011”}).limit(10)
Places v2 place1 = { name: "10gen HQ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [“business”, “recommended”] } db.places.find({zip:”10011”, tags:”business”})
Places v3 place1 = { name: "10gen HQ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [“business”, “cool place”], latlong: [40.0,72.0] } db.places.ensureIndex({latlong:”2d”}) db.places.find({latlong:{$near:[40,70]}})
Places v4 place1 = { name: "10gen HQ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, latlong: [40.0,72.0], tags: [“business”, “cool place”], tips: [ {user:"nosh", time:6/26/2010, tip:"stop by  for office hours on Wednesdays from 4-6pm"},  {.....}, {.....} ] }
Querying your Places Creating your 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]}}) With regular expressions: db.places.find({name: /^ typeaheadstring /) By tag: db.places.find({tags: “business”})
Inserting and updating places Initial data load: db.places.insert(place1) Updating tips: db.places.update({name:"10gen HQ"},  {$push :{tips:  {user:"nosh", time:6/26/2010,  tip:"stop by for office hours on  Wednesdays from 4-6"}}}}
Atomic Updates $set, $unset, $rename $push, $pop, $pull, $addToSet $inc
Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about  checkins
Users user1 = { name: “nosh” email: “nosh@10gen.com”, . . . checkins: [ 4b97e62bf1d8c7152c9ccb74,  5a20e62bf1d8c736ab ] } checkins [] = ObjectId reference to checkin collection
Checkins checkin1 = { place: “10gen HQ”, ts: 6/7/2011 10:12:00, userId: <objectid of user> } Check-in = 2 ops Insert check in object [checkin collection] Update ($push) user object [user collection] Indexes: db.checkins.ensureIndex({place:1, ts:1}) db.checkins.ensureIndex({ts:1})
Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about  checkins
Simple Stats db.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() db.checkins.find().sort(ts:-1)}.limit(50)
Stats with MapReduce mapFunc = 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}})
Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about  checkins
Single Master Deployments Configure as a replica set for automated failover Add more secondaries to scale reads Primary/Master Secondary/Slave
Auto Sharded Deployment Autosharding distributes data among two or more replica sets Mongo Config Server(s) handles distribution & balancing Transparent to applications Primary/Master Secondary/Slave MongoS Mongo Config
Use Cases RDBMS replacement for high-traffic web applications Content Management-type applications Real-time analytics High-speed data logging Web 2.0, Media, SaaS, Gaming, Finance, Telecom, Healthcare
Nosh Petigara [email_address] Director of Product Strategy, 10gen http://mongodb.org http://10gen.com We are hiring! @mongodb [email_address] @noshinosh
MongoDB in Production

More Related Content

PPT
Introduction to MongoDB
PPTX
PPT
2011 Mongo FR - MongoDB introduction
KEY
PPT
2011 mongo FR - scaling with mongodb
PPTX
Back to Basics Webinar 1: Introduction to NoSQL
PPTX
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
PPTX
Back to Basics Webinar 2: Your First MongoDB Application
Introduction to MongoDB
2011 Mongo FR - MongoDB introduction
2011 mongo FR - scaling with mongodb
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 2: Your First MongoDB Application

What's hot (20)

PDF
Indexing
PPTX
Beyond the Basics 2: Aggregation Framework
ODP
MongoDB - Ekino PHP
PDF
An introduction to MongoDB
PPTX
Back to Basics: My First MongoDB Application
PPTX
Back to Basics Webinar 5: Introduction to the Aggregation Framework
PPTX
Back to Basics Webinar 3: Schema Design Thinking in Documents
PPTX
The Aggregation Framework
PDF
Webinar: Working with Graph Data in MongoDB
PPTX
Mongo db queries
PPTX
Webinar: Getting Started with MongoDB - Back to Basics
PPTX
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
PPTX
Agg framework selectgroup feb2015 v2
PDF
Mongo Presentation by Metatagg Solutions
PPTX
Back to Basics Webinar 3: Introduction to Replica Sets
PPTX
Back to Basics, webinar 2: La tua prima applicazione MongoDB
PPT
PhpstudyTokyo MongoDB PHP CakePHP
PPTX
Introduction to MongoDB and Hadoop
PPTX
Indexing Strategies to Help You Scale
KEY
Introduction to MongoDB
Indexing
Beyond the Basics 2: Aggregation Framework
MongoDB - Ekino PHP
An introduction to MongoDB
Back to Basics: My First MongoDB Application
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 3: Schema Design Thinking in Documents
The Aggregation Framework
Webinar: Working with Graph Data in MongoDB
Mongo db queries
Webinar: Getting Started with MongoDB - Back to Basics
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Agg framework selectgroup feb2015 v2
Mongo Presentation by Metatagg Solutions
Back to Basics Webinar 3: Introduction to Replica Sets
Back to Basics, webinar 2: La tua prima applicazione MongoDB
PhpstudyTokyo MongoDB PHP CakePHP
Introduction to MongoDB and Hadoop
Indexing Strategies to Help You Scale
Introduction to MongoDB
Ad

Similar to Introduction to MongoDB (20)

PPT
Nosh slides mongodb web application - mongo philly 2011
PPT
Building Applications with MongoDB - an Introduction
PPT
Building Your First MongoDB Application (Mongo Austin)
PPT
Building a web application with mongo db
KEY
Building your first application w/mongoDB MongoSV2011
PPT
Building web applications with mongo db presentation
PPT
Mongo Web Apps: OSCON 2011
KEY
Building Your First MongoDB Application
PPTX
First app online conf
PPT
9b. Document-Oriented Databases lab
PDF
Latinoware
PPTX
How to leverage what's new in MongoDB 3.6
PPTX
MongoDB Aggregations Indexing and Profiling
PPTX
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
PPTX
1403 app dev series - session 5 - analytics
PDF
Mongoskin - Guilin
PDF
Nosql hands on handout 04
ODP
Leichtgewichtige Webwenwendungen mit dem MEAN-Stack
PDF
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
PPTX
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Nosh slides mongodb web application - mongo philly 2011
Building Applications with MongoDB - an Introduction
Building Your First MongoDB Application (Mongo Austin)
Building a web application with mongo db
Building your first application w/mongoDB MongoSV2011
Building web applications with mongo db presentation
Mongo Web Apps: OSCON 2011
Building Your First MongoDB Application
First app online conf
9b. Document-Oriented Databases lab
Latinoware
How to leverage what's new in MongoDB 3.6
MongoDB Aggregations Indexing and Profiling
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
1403 app dev series - session 5 - analytics
Mongoskin - Guilin
Nosql hands on handout 04
Leichtgewichtige Webwenwendungen mit dem MEAN-Stack
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Ad

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Spectroscopy.pptx food analysis technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Approach and Philosophy of On baking technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Weekly Chronicles - August'25 Week I
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Review of recent advances in non-invasive hemoglobin estimation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Empathic Computing: Creating Shared Understanding
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Programs and apps: productivity, graphics, security and other tools
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Network Security Unit 5.pdf for BCA BBA.
Spectroscopy.pptx food analysis technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Understanding_Digital_Forensics_Presentation.pptx
MIND Revenue Release Quarter 2 2025 Press Release

Introduction to MongoDB

  • 1. http://mongodb.org http://10gen.com Building applications with MongoDB – An introduction MongoNYC – June 7, 2011 Nosh Petigara [email_address] @noshinosh
  • 2. Today’s Talk MongoDB: Data modeling, queries, geospatial, updates, map reduce Using a location-based app as an example Example Works in MongoDB JS shell
  • 3. Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about checkins
  • 4. Documents doc1 = { _id: 4b97e62bf1d8c7152c9ccb74 , key1: value1, key2: value2, key3: {..., ..., ...}, key4: [..., ..., ] }
  • 5. Collections doc1, doc2, doc3 Places Users Checkins doc3, doc4, doc5 doc6, doc7, doc8
  • 6. Places v1 place1 = { name: &quot;10gen HQ”, address: ”134 5 th Avenue 3 rd Floor”, city: &quot;New York”, zip: &quot;10011” } db.places.find({zip:”10011”}).limit(10)
  • 7. Places v2 place1 = { name: &quot;10gen HQ”, address: &quot;17 West 18th Street 8th Floor”, city: &quot;New York”, zip: &quot;10011”, tags: [“business”, “recommended”] } db.places.find({zip:”10011”, tags:”business”})
  • 8. Places v3 place1 = { name: &quot;10gen HQ”, address: &quot;17 West 18th Street 8th Floor”, city: &quot;New York”, zip: &quot;10011”, tags: [“business”, “cool place”], latlong: [40.0,72.0] } db.places.ensureIndex({latlong:”2d”}) db.places.find({latlong:{$near:[40,70]}})
  • 9. Places v4 place1 = { name: &quot;10gen HQ”, address: &quot;17 West 18th Street 8th Floor”, city: &quot;New York”, zip: &quot;10011”, latlong: [40.0,72.0], tags: [“business”, “cool place”], tips: [ {user:&quot;nosh&quot;, time:6/26/2010, tip:&quot;stop by for office hours on Wednesdays from 4-6pm&quot;}, {.....}, {.....} ] }
  • 10. Querying your Places Creating your 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]}}) With regular expressions: db.places.find({name: /^ typeaheadstring /) By tag: db.places.find({tags: “business”})
  • 11. Inserting and updating places Initial data load: db.places.insert(place1) Updating tips: db.places.update({name:&quot;10gen HQ&quot;}, {$push :{tips: {user:&quot;nosh&quot;, time:6/26/2010, tip:&quot;stop by for office hours on Wednesdays from 4-6&quot;}}}}
  • 12. Atomic Updates $set, $unset, $rename $push, $pop, $pull, $addToSet $inc
  • 13. Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about checkins
  • 14. Users user1 = { name: “nosh” email: “nosh@10gen.com”, . . . checkins: [ 4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab ] } checkins [] = ObjectId reference to checkin collection
  • 15. Checkins checkin1 = { place: “10gen HQ”, ts: 6/7/2011 10:12:00, userId: <objectid of user> } Check-in = 2 ops Insert check in object [checkin collection] Update ($push) user object [user collection] Indexes: db.checkins.ensureIndex({place:1, ts:1}) db.checkins.ensureIndex({ts:1})
  • 16. Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about checkins
  • 17. Simple Stats db.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() db.checkins.find().sort(ts:-1)}.limit(50)
  • 18. Stats with MapReduce mapFunc = 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}})
  • 19. Application Goals Places Check ins (1) Q: Current location A: Places near location (2) Add user generated content (3) Record user checkins (4) Stats about checkins
  • 20. Single Master Deployments Configure as a replica set for automated failover Add more secondaries to scale reads Primary/Master Secondary/Slave
  • 21. Auto Sharded Deployment Autosharding distributes data among two or more replica sets Mongo Config Server(s) handles distribution & balancing Transparent to applications Primary/Master Secondary/Slave MongoS Mongo Config
  • 22. Use Cases RDBMS replacement for high-traffic web applications Content Management-type applications Real-time analytics High-speed data logging Web 2.0, Media, SaaS, Gaming, Finance, Telecom, Healthcare
  • 23. Nosh Petigara [email_address] Director of Product Strategy, 10gen http://mongodb.org http://10gen.com We are hiring! @mongodb [email_address] @noshinosh

Editor's Notes

  • #4: Memory mapped files, BSON, indexes, multiple data types, binary files, etc
  • #14: Memory mapped files, BSON, indexes, multiple data types, binary files, etc
  • #17: Memory mapped files, BSON, indexes, multiple data types, binary files, etc
  • #20: Memory mapped files, BSON, indexes, multiple data types, binary files, etc