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

What's hot (20)

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

Similar to Introduction to MongoDB (20)

PPT
Nosh slides mongodb web application - mongo philly 2011
MongoDB
 
PPT
Building Your First MongoDB Application (Mongo Austin)
MongoDB
 
PPT
Building Applications with MongoDB - an Introduction
MongoDB
 
PPT
Building a web application with mongo db
MongoDB
 
PPT
Mongo Web Apps: OSCON 2011
rogerbodamer
 
PPT
Building web applications with mongo db presentation
Murat Çakal
 
KEY
Building your first application w/mongoDB MongoSV2011
Steven Francia
 
KEY
Building Your First MongoDB Application
Rick Copeland
 
PPTX
Webinar: Building Your First Application with MongoDB
MongoDB
 
PPTX
First app online conf
MongoDB
 
PPT
9b. Document-Oriented Databases lab
Fabio Fumarola
 
PPTX
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
PPTX
Spatial MongoDB, Node.JS, and Express - server-side JS for your application
Steven Pousty
 
PDF
MongoDB + GeoServer
MongoDB
 
PDF
Spatial script for Spatial mongo for PHP and Zend
Steven Pousty
 
PPTX
Open Source Mapping with Python, and MongoDB
techprane
 
PPTX
Geoindexing with MongoDB
leafnode
 
PPTX
Building a Location-based platform with MongoDB from Zero.
Ravi Teja
 
PPTX
Getting Started with Geospatial Data in MongoDB
MongoDB
 
PPT
Building Your First MongoDB App ~ Metadata Catalog
hungarianhc
 
Nosh slides mongodb web application - mongo philly 2011
MongoDB
 
Building Your First MongoDB Application (Mongo Austin)
MongoDB
 
Building Applications with MongoDB - an Introduction
MongoDB
 
Building a web application with mongo db
MongoDB
 
Mongo Web Apps: OSCON 2011
rogerbodamer
 
Building web applications with mongo db presentation
Murat Çakal
 
Building your first application w/mongoDB MongoSV2011
Steven Francia
 
Building Your First MongoDB Application
Rick Copeland
 
Webinar: Building Your First Application with MongoDB
MongoDB
 
First app online conf
MongoDB
 
9b. Document-Oriented Databases lab
Fabio Fumarola
 
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
Spatial MongoDB, Node.JS, and Express - server-side JS for your application
Steven Pousty
 
MongoDB + GeoServer
MongoDB
 
Spatial script for Spatial mongo for PHP and Zend
Steven Pousty
 
Open Source Mapping with Python, and MongoDB
techprane
 
Geoindexing with MongoDB
leafnode
 
Building a Location-based platform with MongoDB from Zero.
Ravi Teja
 
Getting Started with Geospatial Data in MongoDB
MongoDB
 
Building Your First MongoDB App ~ Metadata Catalog
hungarianhc
 
Ad

Recently uploaded (20)

DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Ad

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: “[email protected]”, . . . 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