SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
GEOLOCATION IN
                               MONGODB
                            { name: ‘Shashank Tiwari’, web: ‘shanky.org’}




Wednesday, January 16, 13
WHO AM I?



                Entrepreneur, developer, author

                Most recent book: Professional NoSQL (Wiley, 2011)

                Founder : WhatNext Labs, creators of




Wednesday, January 16, 13
DEGREES OF MEASURE



                Latitude

                Longitude




Wednesday, January 16, 13
DEGREE OF LONGITUDE




Wednesday, January 16, 13
GEO IN MONGO




                Is a world in 2D




Wednesday, January 16, 13
MONGO DOC WITH LOC



                { loc : [37.407202, -122.10716] }

                { loc : { x: 37.407202, y: -122.10716} }

                { loc : { lat: 37.407202, lon: -122.10716} }




Wednesday, January 16, 13
INDEX



                db.places.ensureIndex( { loc : "2d" } )

                1 geospatial index per collection




Wednesday, January 16, 13
INDEX RANGE



                db.places.ensureIndex( { loc : "2d" } , { min : -500 , max :
                500 } )




Wednesday, January 16, 13
INDEX PRECISION



                db.places.ensureIndex( { loc : "2d" } , { bits : 26 } )

                Geo-hash precision of 26bits ~ 2 feet




Wednesday, January 16, 13
EXACT QUERIES



                > db.places.find({ loc : [ 37.407202, -122.10716 ]});

                { "_id" : ObjectId("50b69e66e6945f62a019f3a4"), "name" :
                "San Antonio Caltrain", "loc" : [ 37.407202, -122.10716 ] }




Wednesday, January 16, 13
EXPLAIN QUERY PLAN




                db.places.find({ loc : [ 37.407202, -122.10716 ]}).explain();




Wednesday, January 16, 13
COMPOUND INDEX




                db.places.ensureIndex( { loc : "2d", name : 1 } )




Wednesday, January 16, 13
NEAR QUERY



                db.places.find({ loc : { $near : [ 37.407202, -122.10716 ]}});

                Returns points sorted by distance




Wednesday, January 16, 13
WITH MAXDISTANCE


                db.places.find({ loc : { $near : [ 37.407202, -122.10716 ],
                $maxDistance : 0.05}});

                What is the unit of maxDistance? -- for latitude & longitude 1
                degree ~ 69 miles




Wednesday, January 16, 13
GEONEAR QUERY



                db.runCommand({ geoNear : "places", near : [37.407202,
                -122.10716], num : 5 });

                also gives the distance




Wednesday, January 16, 13
MORE WITH GEONEAR



                db.runCommand({ geoNear : "places", near : [37.407202,
                -122.10716], num : 5, type : “DO” });

                parameters: near, num, maxDistance, query




Wednesday, January 16, 13
WITHIN A BOX



                db.places.find({ loc : { $within : { $box : [[39.589821,
                -122.438831], [37.485200, -122.228438]] }}});




Wednesday, January 16, 13
WITHIN A CIRCLE



                db.places.find({ loc : { $within : { $center : [[39.589821,
                -122.438831], 10] }}});




Wednesday, January 16, 13
WITHIN A POLYGON




                Polygon shapes currently cannot be indexed




Wednesday, January 16, 13
SPHERICAL SUPPORT


                geoNear -- spherical : true

                $nearSphere

                $centerSphere

                Order is important, very important -- longitude, latitude




Wednesday, January 16, 13
MULTI LOCATIONS



                db.places.insert({ placesVisitedToday : [ { name : "San
                Antonio Caltrain", loc : [37.407202, -122.10716] }, { name :
                "Datapipe", loc : [37.3336641, -121.8887072] } ] })




Wednesday, January 16, 13
QUERY MULTI LOC



                db.places.ensureIndex( { " placesVisitedToday.loc " : "2d"} )

                use uniqueDocs : true to get unique documents




Wednesday, January 16, 13
Wednesday, January 16, 13
Wednesday, January 16, 13
NEXT TALK



                 Join me to learn MongoDB in an hour!

                Coming soon : Feb 1, 2013




Wednesday, January 16, 13
THANKS


                More questions? web: shanky.org | twitter : @tshanky | email:
                st@treasuryofideas.com

                Download and play with                 on Google Play and
                coming soon to the AppStore.




Wednesday, January 16, 13

Weitere ähnliche Inhalte

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Geolocation in MongoDB

  • 1. GEOLOCATION IN MONGODB { name: ‘Shashank Tiwari’, web: ‘shanky.org’} Wednesday, January 16, 13
  • 2. WHO AM I? Entrepreneur, developer, author Most recent book: Professional NoSQL (Wiley, 2011) Founder : WhatNext Labs, creators of Wednesday, January 16, 13
  • 3. DEGREES OF MEASURE Latitude Longitude Wednesday, January 16, 13
  • 5. GEO IN MONGO Is a world in 2D Wednesday, January 16, 13
  • 6. MONGO DOC WITH LOC { loc : [37.407202, -122.10716] } { loc : { x: 37.407202, y: -122.10716} } { loc : { lat: 37.407202, lon: -122.10716} } Wednesday, January 16, 13
  • 7. INDEX db.places.ensureIndex( { loc : "2d" } ) 1 geospatial index per collection Wednesday, January 16, 13
  • 8. INDEX RANGE db.places.ensureIndex( { loc : "2d" } , { min : -500 , max : 500 } ) Wednesday, January 16, 13
  • 9. INDEX PRECISION db.places.ensureIndex( { loc : "2d" } , { bits : 26 } ) Geo-hash precision of 26bits ~ 2 feet Wednesday, January 16, 13
  • 10. EXACT QUERIES > db.places.find({ loc : [ 37.407202, -122.10716 ]}); { "_id" : ObjectId("50b69e66e6945f62a019f3a4"), "name" : "San Antonio Caltrain", "loc" : [ 37.407202, -122.10716 ] } Wednesday, January 16, 13
  • 11. EXPLAIN QUERY PLAN db.places.find({ loc : [ 37.407202, -122.10716 ]}).explain(); Wednesday, January 16, 13
  • 12. COMPOUND INDEX db.places.ensureIndex( { loc : "2d", name : 1 } ) Wednesday, January 16, 13
  • 13. NEAR QUERY db.places.find({ loc : { $near : [ 37.407202, -122.10716 ]}}); Returns points sorted by distance Wednesday, January 16, 13
  • 14. WITH MAXDISTANCE db.places.find({ loc : { $near : [ 37.407202, -122.10716 ], $maxDistance : 0.05}}); What is the unit of maxDistance? -- for latitude & longitude 1 degree ~ 69 miles Wednesday, January 16, 13
  • 15. GEONEAR QUERY db.runCommand({ geoNear : "places", near : [37.407202, -122.10716], num : 5 }); also gives the distance Wednesday, January 16, 13
  • 16. MORE WITH GEONEAR db.runCommand({ geoNear : "places", near : [37.407202, -122.10716], num : 5, type : “DO” }); parameters: near, num, maxDistance, query Wednesday, January 16, 13
  • 17. WITHIN A BOX db.places.find({ loc : { $within : { $box : [[39.589821, -122.438831], [37.485200, -122.228438]] }}}); Wednesday, January 16, 13
  • 18. WITHIN A CIRCLE db.places.find({ loc : { $within : { $center : [[39.589821, -122.438831], 10] }}}); Wednesday, January 16, 13
  • 19. WITHIN A POLYGON Polygon shapes currently cannot be indexed Wednesday, January 16, 13
  • 20. SPHERICAL SUPPORT geoNear -- spherical : true $nearSphere $centerSphere Order is important, very important -- longitude, latitude Wednesday, January 16, 13
  • 21. MULTI LOCATIONS db.places.insert({ placesVisitedToday : [ { name : "San Antonio Caltrain", loc : [37.407202, -122.10716] }, { name : "Datapipe", loc : [37.3336641, -121.8887072] } ] }) Wednesday, January 16, 13
  • 22. QUERY MULTI LOC db.places.ensureIndex( { " placesVisitedToday.loc " : "2d"} ) use uniqueDocs : true to get unique documents Wednesday, January 16, 13
  • 25. NEXT TALK Join me to learn MongoDB in an hour! Coming soon : Feb 1, 2013 Wednesday, January 16, 13
  • 26. THANKS More questions? web: shanky.org | twitter : @tshanky | email: st@treasuryofideas.com Download and play with on Google Play and coming soon to the AppStore. Wednesday, January 16, 13