SlideShare a Scribd company logo
1 of 34
Download to read offline
MongoDB for mobile app
backends
sf android meetup
08.31.2010
I’ve written my mobile app…
where should I store my data ?
?
Mobile apps do not exist
in a vacuum
• user profile data
• logging
• location-based data collection
• game data (stats, high scores)
• polls and surveys
• user feedback
Do I want to host this
myself ?
Java + Spring + Hibernate ?
Ruby on Rails ?
Hmmm… I will probably
need to build a REST API…
GET, POST, PUT, DELETE
•EC2
•Rackspace
•App Engine*
•MySQL
•SQLServer
•Postgres
•RoR
•J2EE
General approach
REST API
How can this be even simpler and
more awesome?
• “Scalable, open-source, high-
performance, document-oriented
database” - 10gen
• “The database your database could
smell like” - old spice guy
MongoDB is designed to address
two modern DB problems
1. object / relational “impedance mismatch”
2. horizontal scalability
Native drivers in almost every
language
• Java
• Javascript
• Python
• Ruby
• C#
• PHP
• and more…
A paradigm shift…
• Traditional RDMS
– database
– table
– row
• MongoDB
– database
– collection
– document / object
Documents (a.k.a. Objects)
{
_id: 1234,
author: { name: “Bob Jones”, email: “b@b.com” },
post: “In these troubled times I like to …“,
date: { $date: “2010-07-12 13:23UTC” },
location: [ -121.2322, 42.1223222 ],
rating: 2.2,
comments: [
{ user: “jgs32@hotmail.com”,
upVotes: 22,
downVotes: 14,
text: “Great point! I agree” },
{ user: “holly.davidson@gmail.com”,
upVotes: 421,
downVotes: 22,
text: “You are a moron” }
]
}
{
_id: 1234,
author: { name: “Bob Jones”, email: “b@b.com” },
post: “In these troubled times I like to …“,
date: { $date: “2010-07-12 13:23UTC” },
location: [ -121.2322, 42.1223222 ],
rating: 2.2,
comments: [
{ user: “jgs32@hotmail.com”,
upVotes: 22,
downVotes: 14,
text: “Great point! I agree” },
{ user: “holly.davidson@gmail.com”,
upVotes: 421,
downVotes: 22,
text: “You are a moron” }
],
tags: [ “politics”, “Virginia” ]
}
Flexible “schemas”
db.posts.find({ author.name: “mike” })
Dynamic queries
db.posts.find({ rating: { $gt: 2 }})
db.posts.find({ tags: “software” })
db.posts.find().sort({date: -1}).limit(10)
Comment c = {author: “will”,
date: new Date(),
text: “great post!”}
db.posts.update({_id: post._id},
{$push: {comments: c}})
Atomic update operators
Aggregation and Map/Reduce
Focus on scalability and
performance
depth of functionality
scalabilityandperformance
•memcached
•key / value
•RDBMS
•
High performance, fault tolerant
clusters made easy
• master / slave replication
• replica sets
• auto-sharding
MongoDB is great for mobile
• everything is JSON!
– storage model is JSON
– queries are in JSON
– update operators are in JSON
• geospatial indexing built-in
• GridFS
Geospatial indexing
• index on geo coordinate pairs
• search by
– bounding box
– bounding circle (point, radius)
Geospatial indexing
db.places.ensureIndex( { loc: “2d” } )
db.places.find({ loc: { $near : [50, 50] } }).limit(10)
db.places.find({loc: {$within : {$box : [[40,40],[60,60]]}}})
db.places.find({loc: {$within : {$center : [[40,40],10]}}})
Geospatial indexing at
Foursquare
• ~1.3M registered users
• ~615k check-ins a day
• “Who’s here” service tracks last 3 hours for
every user; uses mongo exclusively
• all checkins, tips and venues written to
mongo; reads a mix of mongo / legacy
postgres
GridFS
• distributed filesystem inside MongoDB
• stores large files by splitting them into
smaller documents
• leverages existing sharding and
replication configuration
• stores metadata along with files
• works well behind a CDN
Street cred
• Shutterfly
• Foursquare
• bit.ly
• Sourceforge
• Etsy
• The New York Times
• Business Insider
• Github
• Gilt Groupe
• Sugar CRM
• Electronic Arts
• Evite
• CollegeHumor
• Disqus
• Justin.tv
• Chartbeat
• Hot potato
• Eventbrite
Not so good for
• Complex / multi-operation
transactions
• When you (really) need joins
How can this be even simpler and
more awesome?
• MongoLab provides cloud-hosted
MongoDB
• It’s EC2 hosting + MongoDB + REST
API + awesome admin tools
• http://mongolab.com
GET, POST, PUT, DELETE
EC2
MongoDB
Two ways to use MongoLab
REST API
method 1: REST API
method 2: MongoDB driver
Your application
/databases/<d>/collections
GET
/databases/<d>/collections/<c>
GET
POST
/databases/<d>/collections/<c>/<_id>
GET
PUT
DELETE
/databases/<d>/collections/<c>?[q=<query>]
[&f=<fields>]
[&s=<order>]
[&sk=<skip>]
[&l=<limit>]
GET
MongoLab API
Example app:
GeoPost
• add a GeoPost (email, date, message, location)
• list nearby GeoPosts
Example app:
GeoPost
• POST
URL: https://mongolab.com/api/1/databases/demo/collections/geoposts
data: { “email” : “will@mongolab.com”,
“date” : { “$date” : “2010-02-03 10:21:21 UTC” },
“location” : { “lat” : 41, “long” : -82 },
“message” : “Hello Cleveland!” }
• GET
URL: https://…/geoposts?q={"location":{"$near":{"lat":38,"long":-122}}}
Android SDK makes client-side
easy
• JSON: org.json.*
• REST: org.apache.http.*
HttpClient client = new DefaultHttpClient()
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
String json = convertStreamToString(in);
JSONObject o = new JSONObject(json);
For more info…
• MongoDB / 10Gen
– http://mongodb.org
– http://10gen.com
• MongoLab
– http://mongolab.com
– will@mongolab.com

More Related Content

What's hot

User Data Management with MongoDB
User Data Management with MongoDB User Data Management with MongoDB
User Data Management with MongoDB
MongoDB
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
MongoDB
 
Mongoid in the real world
Mongoid in the real worldMongoid in the real world
Mongoid in the real world
Kevin Faustino
 

What's hot (20)

Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
Socialite, the Open Source Status Feed Part 3: Scaling the Data Feed
Socialite, the Open Source Status Feed Part 3: Scaling the Data FeedSocialite, the Open Source Status Feed Part 3: Scaling the Data Feed
Socialite, the Open Source Status Feed Part 3: Scaling the Data Feed
 
MongoDB and Schema Design
MongoDB and Schema DesignMongoDB and Schema Design
MongoDB and Schema Design
 
Data Modeling for the Real World
Data Modeling for the Real WorldData Modeling for the Real World
Data Modeling for the Real World
 
User Data Management with MongoDB
User Data Management with MongoDB User Data Management with MongoDB
User Data Management with MongoDB
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
 
Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB
 Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB
Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB
 
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
 
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
 
Socialite, the Open Source Status Feed
Socialite, the Open Source Status FeedSocialite, the Open Source Status Feed
Socialite, the Open Source Status Feed
 
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
Socialite, the Open Source Status Feed Part 2: Managing the Social GraphSocialite, the Open Source Status Feed Part 2: Managing the Social Graph
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
 
MongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and ImplicationsMongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and Implications
 
Back to Basics Webinar 3 - Thinking in Documents
Back to Basics Webinar 3 - Thinking in DocumentsBack to Basics Webinar 3 - Thinking in Documents
Back to Basics Webinar 3 - Thinking in Documents
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB Application
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
 
5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB
 
MongoDB & Mongoid with Rails
MongoDB & Mongoid with RailsMongoDB & Mongoid with Rails
MongoDB & Mongoid with Rails
 
Mongoid in the real world
Mongoid in the real worldMongoid in the real world
Mongoid in the real world
 
Back to Basics Webinar 1 - Introduction to NoSQL
Back to Basics Webinar 1 - Introduction to NoSQLBack to Basics Webinar 1 - Introduction to NoSQL
Back to Basics Webinar 1 - Introduction to NoSQL
 

Similar to Learn Learn how to build your mobile back-end with MongoDB

MongoDB Tick Data Presentation
MongoDB Tick Data PresentationMongoDB Tick Data Presentation
MongoDB Tick Data Presentation
MongoDB
 
Accra MongoDB User Group
Accra MongoDB User GroupAccra MongoDB User Group
Accra MongoDB User Group
MongoDB
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
Murat Çakal
 

Similar to Learn Learn how to build your mobile back-end with MongoDB (20)

Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
MongoDB Tick Data Presentation
MongoDB Tick Data PresentationMongoDB Tick Data Presentation
MongoDB Tick Data Presentation
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
 
MongoDB
MongoDBMongoDB
MongoDB
 
Webinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBWebinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDB
 
Accra MongoDB User Group
Accra MongoDB User GroupAccra MongoDB User Group
Accra MongoDB User Group
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
 
Pre-Aggregated Analytics And Social Feeds Using MongoDB
Pre-Aggregated Analytics And Social Feeds Using MongoDBPre-Aggregated Analytics And Social Feeds Using MongoDB
Pre-Aggregated Analytics And Social Feeds Using MongoDB
 
MongoDB Basics
MongoDB BasicsMongoDB Basics
MongoDB Basics
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Migrating to MongoDB: Best Practices
Migrating to MongoDB: Best PracticesMigrating to MongoDB: Best Practices
Migrating to MongoDB: Best Practices
 
Building Your First MongoDB App ~ Metadata Catalog
Building Your First MongoDB App ~ Metadata CatalogBuilding Your First MongoDB App ~ Metadata Catalog
Building Your First MongoDB App ~ Metadata Catalog
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC Python
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
Using MongoDB + Hadoop Together
Using MongoDB + Hadoop TogetherUsing MongoDB + Hadoop Together
Using MongoDB + Hadoop Together
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
 
MongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDB
MongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDBMongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDB
MongoDB Days Silicon Valley: Winning the Dreamforce Hackathon with MongoDB
 

More from Marakana Inc.

Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
Marakana Inc.
 
Why Java Needs Hierarchical Data
Why Java Needs Hierarchical DataWhy Java Needs Hierarchical Data
Why Java Needs Hierarchical Data
Marakana Inc.
 
Pictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User GroupPictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User Group
Marakana Inc.
 
2010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-62010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-6
Marakana Inc.
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)
Marakana Inc.
 

More from Marakana Inc. (20)

Android Services Black Magic by Aleksandar Gargenta
Android Services Black Magic by Aleksandar GargentaAndroid Services Black Magic by Aleksandar Gargenta
Android Services Black Magic by Aleksandar Gargenta
 
JRuby at Square
JRuby at SquareJRuby at Square
JRuby at Square
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for Scala
 
Why Java Needs Hierarchical Data
Why Java Needs Hierarchical DataWhy Java Needs Hierarchical Data
Why Java Needs Hierarchical Data
 
Deep Dive Into Android Security
Deep Dive Into Android SecurityDeep Dive Into Android Security
Deep Dive Into Android Security
 
Securing Android
Securing AndroidSecuring Android
Securing Android
 
Pictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User GroupPictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User Group
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and Techniques
 
2010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-62010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-6
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)
 
What's this jQuery? Where it came from, and how it will drive innovation
What's this jQuery? Where it came from, and how it will drive innovationWhat's this jQuery? Where it came from, and how it will drive innovation
What's this jQuery? Where it came from, and how it will drive innovation
 
jQuery State of the Union - Yehuda Katz
jQuery State of the Union - Yehuda KatzjQuery State of the Union - Yehuda Katz
jQuery State of the Union - Yehuda Katz
 
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
 
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldEfficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
 
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldEfficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
 
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas EneboLearn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
 
Replacing Java Incrementally
Replacing Java IncrementallyReplacing Java Incrementally
Replacing Java Incrementally
 
Learn to Build like you Code with Apache Buildr
Learn to Build like you Code with Apache BuildrLearn to Build like you Code with Apache Buildr
Learn to Build like you Code with Apache Buildr
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Learn Learn how to build your mobile back-end with MongoDB

  • 1. MongoDB for mobile app backends sf android meetup 08.31.2010
  • 2. I’ve written my mobile app… where should I store my data ? ?
  • 3. Mobile apps do not exist in a vacuum • user profile data • logging • location-based data collection • game data (stats, high scores) • polls and surveys • user feedback
  • 4. Do I want to host this myself ? Java + Spring + Hibernate ? Ruby on Rails ? Hmmm… I will probably need to build a REST API…
  • 5. GET, POST, PUT, DELETE •EC2 •Rackspace •App Engine* •MySQL •SQLServer •Postgres •RoR •J2EE General approach REST API
  • 6. How can this be even simpler and more awesome?
  • 7. • “Scalable, open-source, high- performance, document-oriented database” - 10gen • “The database your database could smell like” - old spice guy
  • 8. MongoDB is designed to address two modern DB problems 1. object / relational “impedance mismatch” 2. horizontal scalability
  • 9. Native drivers in almost every language • Java • Javascript • Python • Ruby • C# • PHP • and more…
  • 10. A paradigm shift… • Traditional RDMS – database – table – row • MongoDB – database – collection – document / object
  • 11. Documents (a.k.a. Objects) { _id: 1234, author: { name: “Bob Jones”, email: “b@b.com” }, post: “In these troubled times I like to …“, date: { $date: “2010-07-12 13:23UTC” }, location: [ -121.2322, 42.1223222 ], rating: 2.2, comments: [ { user: “jgs32@hotmail.com”, upVotes: 22, downVotes: 14, text: “Great point! I agree” }, { user: “holly.davidson@gmail.com”, upVotes: 421, downVotes: 22, text: “You are a moron” } ] }
  • 12. { _id: 1234, author: { name: “Bob Jones”, email: “b@b.com” }, post: “In these troubled times I like to …“, date: { $date: “2010-07-12 13:23UTC” }, location: [ -121.2322, 42.1223222 ], rating: 2.2, comments: [ { user: “jgs32@hotmail.com”, upVotes: 22, downVotes: 14, text: “Great point! I agree” }, { user: “holly.davidson@gmail.com”, upVotes: 421, downVotes: 22, text: “You are a moron” } ], tags: [ “politics”, “Virginia” ] } Flexible “schemas”
  • 13. db.posts.find({ author.name: “mike” }) Dynamic queries db.posts.find({ rating: { $gt: 2 }}) db.posts.find({ tags: “software” }) db.posts.find().sort({date: -1}).limit(10)
  • 14. Comment c = {author: “will”, date: new Date(), text: “great post!”} db.posts.update({_id: post._id}, {$push: {comments: c}}) Atomic update operators
  • 16. Focus on scalability and performance
  • 18. High performance, fault tolerant clusters made easy • master / slave replication • replica sets • auto-sharding
  • 19. MongoDB is great for mobile • everything is JSON! – storage model is JSON – queries are in JSON – update operators are in JSON • geospatial indexing built-in • GridFS
  • 20. Geospatial indexing • index on geo coordinate pairs • search by – bounding box – bounding circle (point, radius)
  • 21. Geospatial indexing db.places.ensureIndex( { loc: “2d” } ) db.places.find({ loc: { $near : [50, 50] } }).limit(10) db.places.find({loc: {$within : {$box : [[40,40],[60,60]]}}}) db.places.find({loc: {$within : {$center : [[40,40],10]}}})
  • 22. Geospatial indexing at Foursquare • ~1.3M registered users • ~615k check-ins a day • “Who’s here” service tracks last 3 hours for every user; uses mongo exclusively • all checkins, tips and venues written to mongo; reads a mix of mongo / legacy postgres
  • 23. GridFS • distributed filesystem inside MongoDB • stores large files by splitting them into smaller documents • leverages existing sharding and replication configuration • stores metadata along with files • works well behind a CDN
  • 24. Street cred • Shutterfly • Foursquare • bit.ly • Sourceforge • Etsy • The New York Times • Business Insider • Github • Gilt Groupe • Sugar CRM • Electronic Arts • Evite • CollegeHumor • Disqus • Justin.tv • Chartbeat • Hot potato • Eventbrite
  • 25. Not so good for • Complex / multi-operation transactions • When you (really) need joins
  • 26. How can this be even simpler and more awesome?
  • 27. • MongoLab provides cloud-hosted MongoDB • It’s EC2 hosting + MongoDB + REST API + awesome admin tools • http://mongolab.com
  • 28. GET, POST, PUT, DELETE EC2 MongoDB Two ways to use MongoLab REST API method 1: REST API method 2: MongoDB driver Your application
  • 30. Example app: GeoPost • add a GeoPost (email, date, message, location) • list nearby GeoPosts
  • 31. Example app: GeoPost • POST URL: https://mongolab.com/api/1/databases/demo/collections/geoposts data: { “email” : “will@mongolab.com”, “date” : { “$date” : “2010-02-03 10:21:21 UTC” }, “location” : { “lat” : 41, “long” : -82 }, “message” : “Hello Cleveland!” } • GET URL: https://…/geoposts?q={"location":{"$near":{"lat":38,"long":-122}}}
  • 32.
  • 33. Android SDK makes client-side easy • JSON: org.json.* • REST: org.apache.http.* HttpClient client = new DefaultHttpClient() HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); InputStream in = entity.getContent(); String json = convertStreamToString(in); JSONObject o = new JSONObject(json);
  • 34. For more info… • MongoDB / 10Gen – http://mongodb.org – http://10gen.com • MongoLab – http://mongolab.com – will@mongolab.com