Your SlideShare is downloading. ×
0
GEOLOCATION IN                               MONGODB                            { name: ‘Shashank Tiwari’, web: ‘shanky.or...
WHO AM I?                Entrepreneur, developer, author                Most recent book: Professional NoSQL (Wiley, 2011)...
DEGREES OF MEASURE                Latitude                LongitudeWednesday, January 16, 13
DEGREE OF LONGITUDEWednesday, January 16, 13
GEO IN MONGO                Is a world in 2DWednesday, January 16, 13
MONGO DOC WITH LOC                { loc : [37.407202, -122.10716] }                { loc : { x: 37.407202, y: -122.10716} ...
INDEX                db.places.ensureIndex( { loc : "2d" } )                1 geospatial index per collectionWednesday, Ja...
INDEX RANGE                db.places.ensureIndex( { loc : "2d" } , { min : -500 , max :                500 } )Wednesday, J...
INDEX PRECISION                db.places.ensureIndex( { loc : "2d" } , { bits : 26 } )                Geo-hash precision o...
EXACT QUERIES                > db.places.find({ loc : [ 37.407202, -122.10716 ]});                { "_id" : ObjectId("50b69...
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 sort...
WITH MAXDISTANCE                db.places.find({ loc : { $near : [ 37.407202, -122.10716 ],                $maxDistance : 0...
GEONEAR QUERY                db.runCommand({ geoNear : "places", near : [37.407202,                -122.10716], num : 5 })...
MORE WITH GEONEAR                db.runCommand({ geoNear : "places", near : [37.407202,                -122.10716], num : ...
WITHIN A BOX                db.places.find({ loc : { $within : { $box : [[39.589821,                -122.438831], [37.48520...
WITHIN A CIRCLE                db.places.find({ loc : { $within : { $center : [[39.589821,                -122.438831], 10]...
WITHIN A POLYGON                Polygon shapes currently cannot be indexedWednesday, January 16, 13
SPHERICAL SUPPORT                geoNear -- spherical : true                $nearSphere                $centerSphere      ...
MULTI LOCATIONS                db.places.insert({ placesVisitedToday : [ { name : "San                Antonio Caltrain", l...
QUERY MULTI LOC                db.places.ensureIndex( { " placesVisitedToday.loc " : "2d"} )                use uniqueDocs...
Wednesday, January 16, 13
Wednesday, January 16, 13
NEXT TALK                 Join me to learn MongoDB in an hour!                Coming soon : Feb 1, 2013Wednesday, January ...
THANKS                More questions? web: shanky.org | twitter : @tshanky | email:                st@treasuryofideas.com  ...
Upcoming SlideShare
Loading in...5
×

Geolocation in MongoDB

6,508

Published on

A talk on "Geolocation in MongoDB" at the Silicon Valley MongoDB User Group. (http://www.meetup.com/MongoDB-SV-User-Group/events/91702142/)

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
6,508
On Slideshare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Geolocation in MongoDB"

  1. 1. GEOLOCATION IN MONGODB { name: ‘Shashank Tiwari’, web: ‘shanky.org’}Wednesday, January 16, 13
  2. 2. WHO AM I? Entrepreneur, developer, author Most recent book: Professional NoSQL (Wiley, 2011) Founder : WhatNext Labs, creators ofWednesday, January 16, 13
  3. 3. DEGREES OF MEASURE Latitude LongitudeWednesday, January 16, 13
  4. 4. DEGREE OF LONGITUDEWednesday, January 16, 13
  5. 5. GEO IN MONGO Is a world in 2DWednesday, January 16, 13
  6. 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. 7. INDEX db.places.ensureIndex( { loc : "2d" } ) 1 geospatial index per collectionWednesday, January 16, 13
  8. 8. INDEX RANGE db.places.ensureIndex( { loc : "2d" } , { min : -500 , max : 500 } )Wednesday, January 16, 13
  9. 9. INDEX PRECISION db.places.ensureIndex( { loc : "2d" } , { bits : 26 } ) Geo-hash precision of 26bits ~ 2 feetWednesday, January 16, 13
  10. 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. 11. EXPLAIN QUERY PLAN db.places.find({ loc : [ 37.407202, -122.10716 ]}).explain();Wednesday, January 16, 13
  12. 12. COMPOUND INDEX db.places.ensureIndex( { loc : "2d", name : 1 } )Wednesday, January 16, 13
  13. 13. NEAR QUERY db.places.find({ loc : { $near : [ 37.407202, -122.10716 ]}}); Returns points sorted by distanceWednesday, January 16, 13
  14. 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 milesWednesday, January 16, 13
  15. 15. GEONEAR QUERY db.runCommand({ geoNear : "places", near : [37.407202, -122.10716], num : 5 }); also gives the distanceWednesday, January 16, 13
  16. 16. MORE WITH GEONEAR db.runCommand({ geoNear : "places", near : [37.407202, -122.10716], num : 5, type : “DO” }); parameters: near, num, maxDistance, queryWednesday, January 16, 13
  17. 17. WITHIN A BOX db.places.find({ loc : { $within : { $box : [[39.589821, -122.438831], [37.485200, -122.228438]] }}});Wednesday, January 16, 13
  18. 18. WITHIN A CIRCLE db.places.find({ loc : { $within : { $center : [[39.589821, -122.438831], 10] }}});Wednesday, January 16, 13
  19. 19. WITHIN A POLYGON Polygon shapes currently cannot be indexedWednesday, January 16, 13
  20. 20. SPHERICAL SUPPORT geoNear -- spherical : true $nearSphere $centerSphere Order is important, very important -- longitude, latitudeWednesday, January 16, 13
  21. 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. 22. QUERY MULTI LOC db.places.ensureIndex( { " placesVisitedToday.loc " : "2d"} ) use uniqueDocs : true to get unique documentsWednesday, January 16, 13
  23. 23. Wednesday, January 16, 13
  24. 24. Wednesday, January 16, 13
  25. 25. NEXT TALK Join me to learn MongoDB in an hour! Coming soon : Feb 1, 2013Wednesday, January 16, 13
  26. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×