SlideShare a Scribd company logo
1 of 34
Building your First
MongoDB Application
       Rick Copeland
         @rick446
      http://arborian.com
Who am I?

• Now a consultant, but formerly...
 • Software engineer at SourceForge
 • Author of Essential SQLAlchemy
 • Primarily code Python
What will you learn
     here?
What will you learn
       here?
• Data Modeling
What will you learn
       here?
• Data Modeling
• Queries
What will you learn
       here?
• Data Modeling
• Queries
• Geospatial indexing
What will you learn
       here?
• Data Modeling
• Queries
• Geospatial indexing
• Updates
What will you learn
       here?
• Data Modeling
• Queries
• Geospatial indexing
• Updates
• Map/Reduce
What will you learn
       here?
• Data Modeling
• Queries
• Geospatial indexing
• Updates
• Map/Reduce
• Deployment and Scaling Concerns
What will you learn
       here?
• Data Modeling
• Queries
• Geospatial indexing
• Updates
• Map/Reduce
• Deployment and Scaling Concerns
• Why MongoDB?
Our Application

• Users can create different locations
• Users can “check in” to these locations
• Users can see who else is checked in
• Let’s call it ThreeTriangles (3tri)
3tri Operations
                        Record
         Find nearby
                       checkins
            places



           Places      Checkins



User-generated                    Checkin
   content                         Stats
MongoDB Terminology
  Relational   MongoDB
   Database    Database
    Table      Collection
    Index        Index
    Row        Document
   Column        Field
Documents?
doc1 = {!
  _id: ObjectId('4b97e62bf1d8c7152c9ccb74'),
  key1: value1,!
  key2: value2,
  key3: {..., ..., ...},
  key4: [..., ..., ]
}
Collections
                                  •   No schema
                                      enforcement
doc1,doc2,...     doc5,doc6,...
                                  •   Per-collection...
   Places              Users
                                      •   Querying

                                      •   Indexing
         doc8,doc9,...
                                      •   Updating


            Checkins                  •   Sharding
Places v1
place1 = {!
  name: "Blake Hotel",!
  address: "555 South McDowell Street",
  city: "Charlotte",
  zip: "28204"}

db.places.find({zip:"28204"}).limit(10)
Places v2
place2 = {
  name: "Blake Hotel",!
  address: "555 South McDowell Street",
  city: "Charlotte",
  zip: "28204",
  tags: ["hotel", "recommended"]}

db.places.find({
  zip: "28204", tags: "hotel"}).limit(10)
Places v3
place3 = {
  name: "Blake Hotel",!
  address: "555 South McDowell Street",
  city: "Charlotte",

  zip: "28204",
  tags: ["hotel", "recommended"],
  latlon: [ 35.21, 80.83 ] }

db.places.ensureIndex({latlong:"2d"})
db.places.find({latlong:{$near:[35,80]}})
Places v4
place4 = {
   name: "Blake Hotel",!
   address: "555 South McDowell Street",
   city: "Charlotte",
   zip: "28204",
   tags: ["hotel", "recommended"],
   latlon: [ 35.21, 80.83 ],
   tips: [
      { user: "rick",
        time: ISODateTime(...),
        tip: "Come learn about #self2012"},
      { ... },
      { ... } ] }
Some Queries
/* First, some indexes */
db.places.ensureIndex({tags:1})
db.places.ensureIndex({name:1})
db.places.ensureIndex({latlong:"2d"})

/* Find places */
db.places.find({latlong:{$near:[40,70]}})

/* Regex searching */
db.places.find({name: /^typeaheadstring/)

/* Searching arrays */
db.places.find({tags: "business"})
Inserting and updating
/* Initial data load */
db.places.insert([place1, place2, ...])

/* Update-in-place */
db.places.update(
   { name:"Blake Hotel" },
   { $push : {
      tips: {
         user: "rick",
         time: ISODateTime(...),
         tip: "Come learn about #self2012" }
       } } )
3tri Operations
                        Record
         Find nearby
                       checkins
            places



           Places      Checkins



User-generated                    Checkin
   content                         Stats
Users
user1 = {
   name: "rick",
   email: "rick@arborian.com",
   ...
   checkins: [

ObjectId('4b97e62bf1d8c7152c9ccb74'),
      ... ] }

/* checkins [] = references checkin
   collection _id field */
Checkins
db.checkins.ensureIndex({place:1, ts:1})
db.checkins.ensureIndex({ts:1})

checkin1 = {
   place: {
      id: ObjectId(...),
      name: "Blake Hotel" },
   ts: ISODateTime(...),
   user: {
      id: ObjectId(...), name: "rick" } }
Atomic Updates
•   $set           •   $pull

•   $unset         •   $pullAll

•   $rename        •   $addToSet

•   $push          •   $inc

•   $pushAll       •   $bit

•   $pop
3tri Operations
                        Record
         Find nearby
                       checkins
            places



           Places      Checkins



User-generated                    Checkin
   content                         Stats
Simple Statistics
/* All checkins */
db.checkins.find({"place.name": "Blake Hotel"})

/* Last 10 checkins */
db.checkins.find({"place.name": "Blake Hotel"})
   .sort({ts:-1}).limit(10)

/* Number of checkins today */
db.checkins.find(
   { "place.name": "Blake Hotel",
     ts: { $gt: ISODateTime(...)} })
   .count()
MapReduce
mapFunc = function() {
   emit(this.place.name, 1); }
reduceFunc = function(key, values) {
   return Array.sum(values); }

res = db.checkins.mapReduce(
   mapFunc, reduceFunc, !
   { query: { ts: { $gt: nowminus3hrs } }
     out: {inline: 1} })

res.results = [
   {_id:"Blake Hotel", value: 17}, ...]
Deployment and Scaling
      Options
Single Master
        Deployment
Read / Write            Primary



        Read        Secondary



        Read        Secondary
Auto-Sharding
  Shard 1 (0..10)   Shard 2 (10..20)   Shard 3 (20..30)


          Primary           Primary          Primary



        Secondary        Secondary       Secondary


Config

        Secondary        Secondary       Secondary
Use Cases
• Replace RDBMS for high-traffic web
  applications
• CMS-style applications
• Social and mobile applications
• Real-time analytics, high-speed logging
• Maybe not double-entry bookkeeping
What do you give up?
• No multi-document atomic operations (i.e.
  transactions)
• No server-side JOINs
• No referential integrity constraints
  between documents
• Data model is typically tied to query
  patterns (less flexible than relational DBs)
Questions?
   Please rate this talk at http://svy.mk/L3jM7f

Interested in training? http://Arborian.com/training

MongoDB Info & Downloads: http://mongodb.org


                  Rick Copeland
                     @rick446
                http://arborian.com

More Related Content

What's hot

2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDBantoinegirbal
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsMongoDB
 
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2MongoDB
 
Building Applications with MongoDB - an Introduction
Building Applications with MongoDB - an IntroductionBuilding Applications with MongoDB - an Introduction
Building Applications with MongoDB - an IntroductionMongoDB
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningPuneet Behl
 
Building Your First MongoDB Application (Mongo Austin)
Building Your First MongoDB Application (Mongo Austin)Building Your First MongoDB Application (Mongo Austin)
Building Your First MongoDB Application (Mongo Austin)MongoDB
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Javaantoinegirbal
 
Building a web application with mongo db
Building a web application with mongo dbBuilding a web application with mongo db
Building a web application with mongo dbMongoDB
 
Nosh slides mongodb web application - mongo philly 2011
Nosh slides   mongodb web application - mongo philly 2011Nosh slides   mongodb web application - mongo philly 2011
Nosh slides mongodb web application - mongo philly 2011MongoDB
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLMongoDB
 
NoSQL - An introduction to CouchDB
NoSQL - An introduction to CouchDBNoSQL - An introduction to CouchDB
NoSQL - An introduction to CouchDBJonathan Weiss
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDBWebinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDBMongoDB
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningMongoDB
 
Apache CouchDB Presentation @ Sept. 2104 GTALUG Meeting
Apache CouchDB Presentation @ Sept. 2104 GTALUG MeetingApache CouchDB Presentation @ Sept. 2104 GTALUG Meeting
Apache CouchDB Presentation @ Sept. 2104 GTALUG MeetingMyles Braithwaite
 
MongoDB Europe 2016 - Graph Operations with MongoDB
MongoDB Europe 2016 - Graph Operations with MongoDBMongoDB Europe 2016 - Graph Operations with MongoDB
MongoDB Europe 2016 - Graph Operations with MongoDBMongoDB
 
Webinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsWebinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsMongoDB
 

What's hot (20)

Mongo db presentation
Mongo db presentationMongo db presentation
Mongo db presentation
 
Mongo db for C# Developers
Mongo db for C# DevelopersMongo db for C# Developers
Mongo db for C# Developers
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
 
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
 
Building Applications with MongoDB - an Introduction
Building Applications with MongoDB - an IntroductionBuilding Applications with MongoDB - an Introduction
Building Applications with MongoDB - an Introduction
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
Mongo db for c# developers
Mongo db for c# developersMongo db for c# developers
Mongo db for c# developers
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Building Your First MongoDB Application (Mongo Austin)
Building Your First MongoDB Application (Mongo Austin)Building Your First MongoDB Application (Mongo Austin)
Building Your First MongoDB Application (Mongo Austin)
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Java
 
Building a web application with mongo db
Building a web application with mongo dbBuilding a web application with mongo db
Building a web application with mongo db
 
Nosh slides mongodb web application - mongo philly 2011
Nosh slides   mongodb web application - mongo philly 2011Nosh slides   mongodb web application - mongo philly 2011
Nosh slides mongodb web application - mongo philly 2011
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQL
 
NoSQL - An introduction to CouchDB
NoSQL - An introduction to CouchDBNoSQL - An introduction to CouchDB
NoSQL - An introduction to CouchDB
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDBWebinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDB
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
Apache CouchDB Presentation @ Sept. 2104 GTALUG Meeting
Apache CouchDB Presentation @ Sept. 2104 GTALUG MeetingApache CouchDB Presentation @ Sept. 2104 GTALUG Meeting
Apache CouchDB Presentation @ Sept. 2104 GTALUG Meeting
 
MongoDB Europe 2016 - Graph Operations with MongoDB
MongoDB Europe 2016 - Graph Operations with MongoDBMongoDB Europe 2016 - Graph Operations with MongoDB
MongoDB Europe 2016 - Graph Operations with MongoDB
 
Webinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsWebinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to Basics
 

Viewers also liked

2. limitations
2. limitations2. limitations
2. limitationsin4400
 
3. python intro
3. python   intro3. python   intro
3. python introin4400
 
4. sql
4. sql4. sql
4. sqlin4400
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
4. python functions
4. python   functions4. python   functions
4. python functionsin4400
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Rick Copeland
 
5. outro
5. outro5. outro
5. outroin4400
 
PyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputationPyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputationRanel Padon
 
1. intro
1. intro1. intro
1. introin4400
 
3. database
3. database3. database
3. databasein4400
 
2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates
2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates
2014_07_28_Django環境安裝以及 Django Book Chapter 4: TemplatesKe Wei Louis
 
Intro to Functions Python
Intro to Functions PythonIntro to Functions Python
Intro to Functions Pythonprimeteacher32
 
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and PackagesPython Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and PackagesP3 InfoTech Solutions Pvt. Ltd.
 
Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Managementprimeteacher32
 

Viewers also liked (20)

2. limitations
2. limitations2. limitations
2. limitations
 
3. python intro
3. python   intro3. python   intro
3. python intro
 
4. sql
4. sql4. sql
4. sql
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M17 - FunctionsPython Programming Essentials - M17 - Functions
Python Programming Essentials - M17 - Functions
 
4. python functions
4. python   functions4. python   functions
4. python functions
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
 
5. outro
5. outro5. outro
5. outro
 
PyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputationPyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputation
 
Python session 2
Python session 2Python session 2
Python session 2
 
1. intro
1. intro1. intro
1. intro
 
3. database
3. database3. database
3. database
 
Number Base Part2
Number Base Part2Number Base Part2
Number Base Part2
 
Number Base Part1
Number Base Part1Number Base Part1
Number Base Part1
 
2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates
2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates
2014_07_28_Django環境安裝以及 Django Book Chapter 4: Templates
 
Intro to Functions Python
Intro to Functions PythonIntro to Functions Python
Intro to Functions Python
 
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and PackagesPython Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and Packages
 
Protecting Hosts
Protecting HostsProtecting Hosts
Protecting Hosts
 
Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Management
 

Similar to Building Your First MongoDB Application

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 presentationMurat Çakal
 
Building your first application w/mongoDB MongoSV2011
Building your first application w/mongoDB MongoSV2011Building your first application w/mongoDB MongoSV2011
Building your first application w/mongoDB MongoSV2011Steven Francia
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
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 LawleyNETWAYS
 
First app online conf
First app   online confFirst app   online conf
First app online confMongoDB
 
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 MongoDBMongoDB
 
Geoindexing with MongoDB
Geoindexing with MongoDBGeoindexing with MongoDB
Geoindexing with MongoDBleafnode
 
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)Uwe Printz
 
mongoyeieheheieueheheueuehwwuwuuuwuwh.pptx
mongoyeieheheieueheheueuehwwuwuuuwuwh.pptxmongoyeieheheieueheheueuehwwuwuuuwuwh.pptx
mongoyeieheheieueheheueuehwwuwuuuwuwh.pptxasiwalsanjib7
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDBMongoDB
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsServer Density
 
MongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB
 
Webinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationWebinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationMongoDB
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!Daniel Cousineau
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)MongoDB
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsMongoDB
 

Similar to Building Your First MongoDB Application (20)

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
 
Building your first application w/mongoDB MongoSV2011
Building your first application w/mongoDB MongoSV2011Building your first application w/mongoDB MongoSV2011
Building your first application w/mongoDB MongoSV2011
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
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
 
First app online conf
First app   online confFirst app   online conf
First app online conf
 
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
 
Geoindexing with MongoDB
Geoindexing with MongoDBGeoindexing with MongoDB
Geoindexing with MongoDB
 
Latinoware
LatinowareLatinoware
Latinoware
 
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)
 
mongoyeieheheieueheheueuehwwuwuuuwuwh.pptx
mongoyeieheheieueheheueuehwwuwuuuwuwh.pptxmongoyeieheheieueheheueuehwwuwuuuwuwh.pptx
mongoyeieheheieueheheueuehwwuwuuuwuwh.pptx
 
Mongodb
MongodbMongodb
Mongodb
 
MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
 
MongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: Sharding
 
Mongodb
MongodbMongodb
Mongodb
 
Webinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationWebinar: Index Tuning and Evaluation
Webinar: Index Tuning and Evaluation
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 

More from Rick Copeland

Schema Design at Scale
Schema Design at ScaleSchema Design at Scale
Schema Design at ScaleRick Copeland
 
Chef on MongoDB and Pyramid
Chef on MongoDB and PyramidChef on MongoDB and Pyramid
Chef on MongoDB and PyramidRick Copeland
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDBRick Copeland
 
Chef on Python and MongoDB
Chef on Python and MongoDBChef on Python and MongoDB
Chef on Python and MongoDBRick Copeland
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioRick Copeland
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRealtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRick Copeland
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRick Copeland
 
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeAllura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeRick Copeland
 
MongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBMongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBRick Copeland
 

More from Rick Copeland (10)

Schema Design at Scale
Schema Design at ScaleSchema Design at Scale
Schema Design at Scale
 
Chef on MongoDB and Pyramid
Chef on MongoDB and PyramidChef on MongoDB and Pyramid
Chef on MongoDB and Pyramid
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDB
 
Chef on Python and MongoDB
Chef on Python and MongoDBChef on Python and MongoDB
Chef on Python and MongoDB
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRealtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and Python
 
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForgeAllura - an Open Source MongoDB Based Document Oriented SourceForge
Allura - an Open Source MongoDB Based Document Oriented SourceForge
 
MongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBMongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDB
 

Recently uploaded

[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.pdfhans926745
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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...apidays
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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...Martijn de Jong
 
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 2024The Digital Insurer
 
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 productivityPrincipled Technologies
 

Recently uploaded (20)

[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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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...
 
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
 

Building Your First MongoDB Application

  • 1. Building your First MongoDB Application Rick Copeland @rick446 http://arborian.com
  • 2. Who am I? • Now a consultant, but formerly... • Software engineer at SourceForge • Author of Essential SQLAlchemy • Primarily code Python
  • 3. What will you learn here?
  • 4. What will you learn here? • Data Modeling
  • 5. What will you learn here? • Data Modeling • Queries
  • 6. What will you learn here? • Data Modeling • Queries • Geospatial indexing
  • 7. What will you learn here? • Data Modeling • Queries • Geospatial indexing • Updates
  • 8. What will you learn here? • Data Modeling • Queries • Geospatial indexing • Updates • Map/Reduce
  • 9. What will you learn here? • Data Modeling • Queries • Geospatial indexing • Updates • Map/Reduce • Deployment and Scaling Concerns
  • 10. What will you learn here? • Data Modeling • Queries • Geospatial indexing • Updates • Map/Reduce • Deployment and Scaling Concerns • Why MongoDB?
  • 11. Our Application • Users can create different locations • Users can “check in” to these locations • Users can see who else is checked in • Let’s call it ThreeTriangles (3tri)
  • 12. 3tri Operations Record Find nearby checkins places Places Checkins User-generated Checkin content Stats
  • 13. MongoDB Terminology Relational MongoDB Database Database Table Collection Index Index Row Document Column Field
  • 14. Documents? doc1 = {! _id: ObjectId('4b97e62bf1d8c7152c9ccb74'), key1: value1,! key2: value2, key3: {..., ..., ...}, key4: [..., ..., ] }
  • 15. Collections • No schema enforcement doc1,doc2,... doc5,doc6,... • Per-collection... Places Users • Querying • Indexing doc8,doc9,... • Updating Checkins • Sharding
  • 16. Places v1 place1 = {! name: "Blake Hotel",! address: "555 South McDowell Street", city: "Charlotte", zip: "28204"} db.places.find({zip:"28204"}).limit(10)
  • 17. Places v2 place2 = { name: "Blake Hotel",! address: "555 South McDowell Street", city: "Charlotte", zip: "28204", tags: ["hotel", "recommended"]} db.places.find({ zip: "28204", tags: "hotel"}).limit(10)
  • 18. Places v3 place3 = { name: "Blake Hotel",! address: "555 South McDowell Street", city: "Charlotte", zip: "28204", tags: ["hotel", "recommended"], latlon: [ 35.21, 80.83 ] } db.places.ensureIndex({latlong:"2d"}) db.places.find({latlong:{$near:[35,80]}})
  • 19. Places v4 place4 = { name: "Blake Hotel",! address: "555 South McDowell Street", city: "Charlotte", zip: "28204", tags: ["hotel", "recommended"], latlon: [ 35.21, 80.83 ], tips: [ { user: "rick", time: ISODateTime(...), tip: "Come learn about #self2012"}, { ... }, { ... } ] }
  • 20. Some Queries /* First, some indexes */ db.places.ensureIndex({tags:1}) db.places.ensureIndex({name:1}) db.places.ensureIndex({latlong:"2d"}) /* Find places */ db.places.find({latlong:{$near:[40,70]}}) /* Regex searching */ db.places.find({name: /^typeaheadstring/) /* Searching arrays */ db.places.find({tags: "business"})
  • 21. Inserting and updating /* Initial data load */ db.places.insert([place1, place2, ...]) /* Update-in-place */ db.places.update( { name:"Blake Hotel" }, { $push : { tips: { user: "rick", time: ISODateTime(...), tip: "Come learn about #self2012" } } } )
  • 22. 3tri Operations Record Find nearby checkins places Places Checkins User-generated Checkin content Stats
  • 23. Users user1 = { name: "rick", email: "rick@arborian.com", ... checkins: [ ObjectId('4b97e62bf1d8c7152c9ccb74'), ... ] } /* checkins [] = references checkin collection _id field */
  • 24. Checkins db.checkins.ensureIndex({place:1, ts:1}) db.checkins.ensureIndex({ts:1}) checkin1 = { place: { id: ObjectId(...), name: "Blake Hotel" }, ts: ISODateTime(...), user: { id: ObjectId(...), name: "rick" } }
  • 25. Atomic Updates • $set • $pull • $unset • $pullAll • $rename • $addToSet • $push • $inc • $pushAll • $bit • $pop
  • 26. 3tri Operations Record Find nearby checkins places Places Checkins User-generated Checkin content Stats
  • 27. Simple Statistics /* All checkins */ db.checkins.find({"place.name": "Blake Hotel"}) /* Last 10 checkins */ db.checkins.find({"place.name": "Blake Hotel"}) .sort({ts:-1}).limit(10) /* Number of checkins today */ db.checkins.find( { "place.name": "Blake Hotel", ts: { $gt: ISODateTime(...)} }) .count()
  • 28. MapReduce mapFunc = function() { emit(this.place.name, 1); } reduceFunc = function(key, values) { return Array.sum(values); } res = db.checkins.mapReduce( mapFunc, reduceFunc, ! { query: { ts: { $gt: nowminus3hrs } } out: {inline: 1} }) res.results = [ {_id:"Blake Hotel", value: 17}, ...]
  • 30. Single Master Deployment Read / Write Primary Read Secondary Read Secondary
  • 31. Auto-Sharding Shard 1 (0..10) Shard 2 (10..20) Shard 3 (20..30) Primary Primary Primary Secondary Secondary Secondary Config Secondary Secondary Secondary
  • 32. Use Cases • Replace RDBMS for high-traffic web applications • CMS-style applications • Social and mobile applications • Real-time analytics, high-speed logging • Maybe not double-entry bookkeeping
  • 33. What do you give up? • No multi-document atomic operations (i.e. transactions) • No server-side JOINs • No referential integrity constraints between documents • Data model is typically tied to query patterns (less flexible than relational DBs)
  • 34. Questions? Please rate this talk at http://svy.mk/L3jM7f Interested in training? http://Arborian.com/training MongoDB Info & Downloads: http://mongodb.org Rick Copeland @rick446 http://arborian.com

Editor's Notes

  1. \n
  2. SF - early adopters of MongoDB (0.8), so we went through some of the growing pains\nSQLAlchemy - I don’t hate SQL!\nKnow Python best, but also C, C++, etc.\n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. Tend to not have auto-increment keys\nStandard JSON values + a few new primitives\nEmbedded docs & arrays OK (and encouraged!)\n
  14. \n
  15. Lots of places, hard to find the one you need\n
  16. Better, now at least we’re just looking for hotels, still too many\n
  17. Results sorted by distance\n
  18. Embedded tips for data locality\n
  19. Regex has same benefits and drawbacks as LIKE in sql -- prefix queries are your friend!\n
  20. Lots of in-place operators so you can update your document atomically (makes transactionlessness less important)\n
  21. So we’ve mostly covered the “Places” side, now let’s look at “Checkins”\n
  22. \n
  23. Checking in inserts checkin and then $pushes user object\n
  24. You can also “reach inside” your objects for updating\n
  25. \n
  26. \n
  27. Flexible output options for dumping results in a collection\n
  28. \n
  29. \n
  30. Data automatically balanced between replica sets\nConfig server stores ‘chunk’ locations\nTransparent to applications\n
  31. \n
  32. No transactions, but doc model is rich enough to do without in many apps\nNo server-side JOIN, but can be emulated in client (use $in)\nNo referential integrity, but 1:N joins become embedded documents\nData model *can* be relational, but you give up performance (and introduce integrity issues, etc) - many will just denormalize data to get both flexibility and performance at the expense of application complexity.\n
  33. \n