SlideShare a Scribd company logo
http://mongodb.org http://10gen.com Building applications with MongoDB – An introduction  Roger Bodamer [email_address] @rogerb
Today ’s Talk Developing your first Web Application with MongoDB What is MongoDB, Platforms and availability Data Modeling, queries and geospatial queries Location bases App Example uses MongoDB Javascript shell
Why MongoDB Intrinsic support for agile development Super low latency access to your data Very little CPU overhead No Additional caching layer required Built in Replication and Horizontal Scaling support
MongoDB Document Oriented Database Data is stored in documents, not tables / relations MongoDB is Implemented in C++ for best performance Platforms 32/64 bit Windows Linux, Mac OS-X, FreeBSD,  Solaris Language drivers for: Ruby / Ruby-on-Rails  Java C# JavaScript  C / C++  Erlang  Python, Perl others..... and much more ! ..
Design Want to build an app where users can check in to a location Leave notes or comments about that location Iterative Approach: Decide requirements Design documents Rinse, repeat :-)
Requirements Locations Need to store locations (Offices, Restaurants etc) Want to be able to store name, address and tags Maybe User Generated Content, i.e. tips / small notes ?  Want to be able to find other locations nearby
Requirements Locations Need to store locations (Offices, Restaurants etc) Want to be able to store name, address and tags Maybe User Generated Content, i.e. tips / small notes ?  Want to be able to find other locations nearby Checkins User should be able to ‘check in’ to a location Want to be able to generate statistics
Terminology RDBMS Mongo Table, View Collection Row(s) JSON Document Index Index Join Embedded Document Partition Shard Partition Key Shard Key
Collections loc1, loc2, loc3 Locations Users User1, User2
JSON Sample Doc {  _id  : ObjectId("4c4ba5c0672c685e5e8aabf3"), author  : "roger",  date  : "Sat Jul 24 2010 19:47:11 GMT-0700 (PDT)",  text  : ”MongoSF",  tags  : [ ”San Francisco", ”MongoDB" ] }  Notes: -  _id  is unique, but can be anything you’d like
BSON JSON has powerful, but limited set of datatypes Mongo extends datypes with Date, Int types, Id, … MongoDB stores data in BSON BSON is a binary representation of JSON Optimized for performance and navigational abilities Also compression See bsonspec.org
Locations v1 location1= { name: "10gen East Coast ”, address: ”134 5 th  Avenue 3 rd  Floor”, city: "New York”, zip: "10011” }
Places v1 location1= { name: "10gen East Coast ”, address: ”134 5 th  Avenue 3 rd  Floor”, city: "New York”, zip: "10011” } db.locations.find({zip: ”10011”}).limit(10)
Places v2 location1 = { name: "10gen East Coast ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [ “business”, “mongodb”] }
Places v2 location1 = { name: "10gen East Coast ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [ “business”, “mongodb”] } db.locations.find({zip: ”10011”, tags:”business”})
Places v3 location1 = { name: "10gen East Coast ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [ “business”, “mongodb”], latlong: [40.0,72.0] }
Places v3 location1 = { name: "10gen East Coast ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [ “business”, “cool place”], latlong: [40.0,72.0] } db.locations.ensureIndex({latlong: ”2d”})
Places v3 location1 = { 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.locations.ensureIndex({latlong: ”2d”}) db.locations.find({latlong:{$near:[40,70]}})
Places v4 location1 = { 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.locations.ensureIndex({tags:1}) db.locations.ensureIndex({name:1}) db.locations.ensureIndex({latlong: ”2d”}) Finding places: db. locations .find({latlong:{$near:[40,70]}}) With regular expressions: db. locations .find({name: /^ typeaheadstring /) By tag: db. locations .find({tags:  “business”})
Inserting and updating locations Initial data load: db.locations.insert(place1) Using update to Add tips: db.locations.update({name:"10gen HQ"},  {$push :{tips:    {user:"nosh", time:6/26/2010,    tip:"stop by for office hours on    Wednesdays from 4-6"}}}}
Requirements Locations Need to store locations (Offices, Restaurants etc) Want to be able to store name, address and tags Maybe User Generated Content, i.e. tips / small notes ?  Want to be able to find other locations nearby Checkins User should be able to ‘check in’ to a location Want to be able to generate statistics
Users user1 = { name:  “nosh” email:  “nosh@10gen.com”, . . . checkins: [{   location:  “10gen HQ”, ts: 9/20/2010 10:12:00, … }, … ] }
Simple Stats db.users.find({‘checkins.location’:  “10gen HQ”) db.checkins.find({‘checkins.location’:  “10gen HQ”}) .sort({ts:-1}).limit(10) db.checkins.find({‘checkins.location’:  “10gen HQ”,  ts: {$gt: midnight}}).count()
Alternative user1 = { name:  “nosh” email:  “nosh@10gen.com”, . . . checkins: [ 4b97e62bf1d8c7152c9ccb74,  5a20e62bf1d8c736ab ] } checkins [] = ObjectId reference to locations collection
User Check in Check-in = 2 ops read location to obtain location id Update ($push) location id to user object Queries: find all locations where a user checked in:  checkin_array = db.users.find({..}, {checkins:true}).checkins db.location.find({_id:{$in: checkin_array}})
Unsharded Deployment Configure as a replica set for automated failover Async replication between nodes Add more secondaries to scale reads Secondary Primary Secondary
Sharded Deployment Autosharding distributes data among two or more replica sets Mongo Config Server(s) handles distribution & balancing Transparent to applications Secondary Primary MongoS 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
http://mongodb.org http://10gen.com 10Gen is hiring!  @mongodb [email_address] @rogerb

More Related Content

PPTX
Scalable Event Analytics with MongoDB & Ruby on Rails
PPTX
Sharding
PPTX
MongoDB's New Aggregation framework
KEY
MongoFr : MongoDB as a log Collector
PPT
MongoDB Basic Concepts
PPTX
Back to Basics Spanish 4 Introduction to sharding
PDF
Mongodb
PPTX
High Performance Applications with MongoDB
Scalable Event Analytics with MongoDB & Ruby on Rails
Sharding
MongoDB's New Aggregation framework
MongoFr : MongoDB as a log Collector
MongoDB Basic Concepts
Back to Basics Spanish 4 Introduction to sharding
Mongodb
High Performance Applications with MongoDB

What's hot (20)

PPTX
Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB
PDF
Back to Basics 2017: Mí primera aplicación MongoDB
PPTX
Intro To Mongo Db
PPTX
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
PPTX
Back to Basics Webinar 2: Your First MongoDB Application
PPTX
Social Analytics with MongoDB
PPTX
MongoDB 101
KEY
KEY
Practical Ruby Projects With Mongo Db
ODP
MongoDB : The Definitive Guide
PPTX
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
PDF
MongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDB
PDF
Webinar: Developing with the modern App Stack: MEAN and MERN (with Angular2 a...
PPTX
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
PPTX
Attack monitoring using ElasticSearch Logstash and Kibana
PDF
mongoDB Performance
PPTX
Back to Basics Webinar 1: Introduction to NoSQL
PPTX
Back to Basics Spanish Webinar 3 - Introducción a los replica sets
PDF
MongoDB for Analytics
PDF
Introduction to MongoDB
Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDB
Intro To Mongo Db
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Back to Basics Webinar 2: Your First MongoDB Application
Social Analytics with MongoDB
MongoDB 101
Practical Ruby Projects With Mongo Db
MongoDB : The Definitive Guide
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
MongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDB
Webinar: Developing with the modern App Stack: MEAN and MERN (with Angular2 a...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
Attack monitoring using ElasticSearch Logstash and Kibana
mongoDB Performance
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Spanish Webinar 3 - Introducción a los replica sets
MongoDB for Analytics
Introduction to MongoDB
Ad

Viewers also liked (20)

KEY
Mongoose v3 :: The Future is Bright
PDF
Grid FS
PPT
Mongo db sharding
PDF
[C5]deview 2012 nodejs
PDF
MongoDB & Hadoop: Flexible Hourly Batch Processing Model
PDF
프론트엔드 웹앱 프레임웍 - Bootstrap, Backbone 그리고 AngularJS
PDF
[H3 2012] 내컴에선 잘되던데? - vagrant로 서버와 동일한 개발환경 꾸미기
PDF
RESTful API Design, Second Edition
KEY
Meteor 0.3.6 Preview
PDF
The SPDY Protocol
PPTX
Becoming Node.js ninja on Cloud Foundry
PPTX
Testing nodejs apps
PDF
FIFA 온라인 3의 MongoDB 사용기
PPT
High Availabiltity & Replica Sets with mongoDB
PPTX
React in Native Apps - Meetup React - 20150409
PPTX
소셜게임 서버 개발 관점에서 본 Node.js의 장단점과 대안
PDF
React JS and why it's awesome
PDF
Module, AMD, RequireJS
PDF
Asynchronous Module Definition (AMD)
PPTX
HTML5 Real-Time and Connectivity
Mongoose v3 :: The Future is Bright
Grid FS
Mongo db sharding
[C5]deview 2012 nodejs
MongoDB & Hadoop: Flexible Hourly Batch Processing Model
프론트엔드 웹앱 프레임웍 - Bootstrap, Backbone 그리고 AngularJS
[H3 2012] 내컴에선 잘되던데? - vagrant로 서버와 동일한 개발환경 꾸미기
RESTful API Design, Second Edition
Meteor 0.3.6 Preview
The SPDY Protocol
Becoming Node.js ninja on Cloud Foundry
Testing nodejs apps
FIFA 온라인 3의 MongoDB 사용기
High Availabiltity & Replica Sets with mongoDB
React in Native Apps - Meetup React - 20150409
소셜게임 서버 개발 관점에서 본 Node.js의 장단점과 대안
React JS and why it's awesome
Module, AMD, RequireJS
Asynchronous Module Definition (AMD)
HTML5 Real-Time and Connectivity
Ad

Similar to Mongo Web Apps: OSCON 2011 (20)

PPT
Building web applications with mongo db presentation
PPT
Building Your First MongoDB Application (Mongo Austin)
PPT
Building Applications with MongoDB - an Introduction
PPT
Building a web application with mongo db
PPT
Nosh slides mongodb web application - mongo philly 2011
PPT
Introduction to MongoDB
KEY
Building Your First MongoDB Application
PPTX
First app online conf
KEY
Building your first application w/mongoDB MongoSV2011
PPTX
Webinar: Building Your First Application with MongoDB
PPTX
Building a Location-based platform with MongoDB from Zero.
PPTX
Webinar: General Technical Overview of MongoDB for Dev Teams
PDF
MongoDB + GeoServer
PPTX
Geoindexing with MongoDB
PDF
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
PPTX
Spatial MongoDB, Node.JS, and Express - server-side JS for your application
PPT
MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup
PPTX
Open Source Mapping with Python, and MongoDB
PPTX
Mongo db intro new
PPTX
Getting Started with Geospatial Data in MongoDB
Building web applications with mongo db presentation
Building Your First MongoDB Application (Mongo Austin)
Building Applications with MongoDB - an Introduction
Building a web application with mongo db
Nosh slides mongodb web application - mongo philly 2011
Introduction to MongoDB
Building Your First MongoDB Application
First app online conf
Building your first application w/mongoDB MongoSV2011
Webinar: Building Your First Application with MongoDB
Building a Location-based platform with MongoDB from Zero.
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB + GeoServer
Geoindexing with MongoDB
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
Spatial MongoDB, Node.JS, and Express - server-side JS for your application
MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup
Open Source Mapping with Python, and MongoDB
Mongo db intro new
Getting Started with Geospatial Data in MongoDB

More from rogerbodamer (6)

PDF
Thoughts on consistency models
PDF
Intro to MongoDB and datamodeling
KEY
Thoughts on MongoDB Analytics
PDF
Mongo db japan
PDF
Deployment
KEY
Schema Design with MongoDB
Thoughts on consistency models
Intro to MongoDB and datamodeling
Thoughts on MongoDB Analytics
Mongo db japan
Deployment
Schema Design with MongoDB

Recently uploaded (20)

PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
1. Introduction to Computer Programming.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
project resource management chapter-09.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
A Presentation on Artificial Intelligence
PDF
Hybrid model detection and classification of lung cancer
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
Heart disease approach using modified random forest and particle swarm optimi...
1. Introduction to Computer Programming.pptx
A comparative analysis of optical character recognition models for extracting...
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
1 - Historical Antecedents, Social Consideration.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Group 1 Presentation -Planning and Decision Making .pptx
project resource management chapter-09.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation_ Review paper, used for researhc scholars
Unlocking AI with Model Context Protocol (MCP)
A comparative study of natural language inference in Swahili using monolingua...
A Presentation on Artificial Intelligence
Hybrid model detection and classification of lung cancer
TLE Review Electricity (Electricity).pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Web App vs Mobile App What Should You Build First.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf

Mongo Web Apps: OSCON 2011

  • 1. http://mongodb.org http://10gen.com Building applications with MongoDB – An introduction Roger Bodamer [email_address] @rogerb
  • 2. Today ’s Talk Developing your first Web Application with MongoDB What is MongoDB, Platforms and availability Data Modeling, queries and geospatial queries Location bases App Example uses MongoDB Javascript shell
  • 3. Why MongoDB Intrinsic support for agile development Super low latency access to your data Very little CPU overhead No Additional caching layer required Built in Replication and Horizontal Scaling support
  • 4. MongoDB Document Oriented Database Data is stored in documents, not tables / relations MongoDB is Implemented in C++ for best performance Platforms 32/64 bit Windows Linux, Mac OS-X, FreeBSD, Solaris Language drivers for: Ruby / Ruby-on-Rails Java C# JavaScript C / C++ Erlang Python, Perl others..... and much more ! ..
  • 5. Design Want to build an app where users can check in to a location Leave notes or comments about that location Iterative Approach: Decide requirements Design documents Rinse, repeat :-)
  • 6. Requirements Locations Need to store locations (Offices, Restaurants etc) Want to be able to store name, address and tags Maybe User Generated Content, i.e. tips / small notes ? Want to be able to find other locations nearby
  • 7. Requirements Locations Need to store locations (Offices, Restaurants etc) Want to be able to store name, address and tags Maybe User Generated Content, i.e. tips / small notes ? Want to be able to find other locations nearby Checkins User should be able to ‘check in’ to a location Want to be able to generate statistics
  • 8. Terminology RDBMS Mongo Table, View Collection Row(s) JSON Document Index Index Join Embedded Document Partition Shard Partition Key Shard Key
  • 9. Collections loc1, loc2, loc3 Locations Users User1, User2
  • 10. JSON Sample Doc { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", date : "Sat Jul 24 2010 19:47:11 GMT-0700 (PDT)", text : ”MongoSF", tags : [ ”San Francisco", ”MongoDB" ] } Notes: - _id is unique, but can be anything you’d like
  • 11. BSON JSON has powerful, but limited set of datatypes Mongo extends datypes with Date, Int types, Id, … MongoDB stores data in BSON BSON is a binary representation of JSON Optimized for performance and navigational abilities Also compression See bsonspec.org
  • 12. Locations v1 location1= { name: "10gen East Coast ”, address: ”134 5 th Avenue 3 rd Floor”, city: "New York”, zip: "10011” }
  • 13. Places v1 location1= { name: "10gen East Coast ”, address: ”134 5 th Avenue 3 rd Floor”, city: "New York”, zip: "10011” } db.locations.find({zip: ”10011”}).limit(10)
  • 14. Places v2 location1 = { name: "10gen East Coast ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [ “business”, “mongodb”] }
  • 15. Places v2 location1 = { name: "10gen East Coast ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [ “business”, “mongodb”] } db.locations.find({zip: ”10011”, tags:”business”})
  • 16. Places v3 location1 = { name: "10gen East Coast ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [ “business”, “mongodb”], latlong: [40.0,72.0] }
  • 17. Places v3 location1 = { name: "10gen East Coast ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [ “business”, “cool place”], latlong: [40.0,72.0] } db.locations.ensureIndex({latlong: ”2d”})
  • 18. Places v3 location1 = { 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.locations.ensureIndex({latlong: ”2d”}) db.locations.find({latlong:{$near:[40,70]}})
  • 19. Places v4 location1 = { 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"}, {.....}, ] }
  • 20. Querying your Places Creating your indexes db.locations.ensureIndex({tags:1}) db.locations.ensureIndex({name:1}) db.locations.ensureIndex({latlong: ”2d”}) Finding places: db. locations .find({latlong:{$near:[40,70]}}) With regular expressions: db. locations .find({name: /^ typeaheadstring /) By tag: db. locations .find({tags: “business”})
  • 21. Inserting and updating locations Initial data load: db.locations.insert(place1) Using update to Add tips: db.locations.update({name:"10gen HQ"}, {$push :{tips: {user:"nosh", time:6/26/2010, tip:"stop by for office hours on Wednesdays from 4-6"}}}}
  • 22. Requirements Locations Need to store locations (Offices, Restaurants etc) Want to be able to store name, address and tags Maybe User Generated Content, i.e. tips / small notes ? Want to be able to find other locations nearby Checkins User should be able to ‘check in’ to a location Want to be able to generate statistics
  • 23. Users user1 = { name: “nosh” email: “nosh@10gen.com”, . . . checkins: [{ location: “10gen HQ”, ts: 9/20/2010 10:12:00, … }, … ] }
  • 24. Simple Stats db.users.find({‘checkins.location’: “10gen HQ”) db.checkins.find({‘checkins.location’: “10gen HQ”}) .sort({ts:-1}).limit(10) db.checkins.find({‘checkins.location’: “10gen HQ”, ts: {$gt: midnight}}).count()
  • 25. Alternative user1 = { name: “nosh” email: “nosh@10gen.com”, . . . checkins: [ 4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab ] } checkins [] = ObjectId reference to locations collection
  • 26. User Check in Check-in = 2 ops read location to obtain location id Update ($push) location id to user object Queries: find all locations where a user checked in: checkin_array = db.users.find({..}, {checkins:true}).checkins db.location.find({_id:{$in: checkin_array}})
  • 27. Unsharded Deployment Configure as a replica set for automated failover Async replication between nodes Add more secondaries to scale reads Secondary Primary Secondary
  • 28. Sharded Deployment Autosharding distributes data among two or more replica sets Mongo Config Server(s) handles distribution & balancing Transparent to applications Secondary Primary MongoS config
  • 29. 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

Editor's Notes

  • #2: 1 doc can have multiple of locations and index on it.
  • #7: Memory mapped files, BSON, indexes, multiple data types, binary files, etc @ main datasets: places and checkins use cases: given current loc find places nearby; add notes to locations Record checkins Generate stats about checkins
  • #8: Memory mapped files, BSON, indexes, multiple data types, binary files, etc @ main datasets: places and checkins use cases: given current loc find places nearby; add notes to locations Record checkins Generate stats about checkins
  • #10: Documents go into collections Todays app: users , places, checkins
  • #17: Latlong are actually real lat / long points $near gives you the closest 100
  • #18: Latlong are actually real lat / long points $near gives you the closest 100
  • #19: Latlong are actually real lat / long points $near gives you the closest 100
  • #23: Memory mapped files, BSON, indexes, multiple data types, binary files, etc @ main datasets: places and checkins use cases: given current loc find places nearby; add notes to locations Record checkins Generate stats about checkins