Geolocation in mongodb
 

Geolocation in mongodb

on

  • 8,131 views

Shashank Tiwari goes through the basics of Geolocation queries and indexing in MongoDB.

Shashank Tiwari goes through the basics of Geolocation queries and indexing in MongoDB.

Statistics

Views

Total Views
8,131
Views on SlideShare
5,422
Embed Views
2,709

Actions

Likes
10
Downloads
37
Comments
0

16 Embeds 2,709

http://shanky.org 2340
http://shashanktiwari.com 137
http://www.shashanktiwari.com 92
http://digg.com 59
http://www.sys-con.com 22
http://abtasty.com 14
http://www.linkedin.com 14
https://www.linkedin.com 11
http://www.365dailyjournal.com 5
http://shashanktiwari.ulitzer.com 5
http://www.shanky.org. 3
https://twitter.com 3
http://prlog.ru 2
http://translate.googleusercontent.com 1
http://twimblr.appspot.com 1
http://www.pearltrees.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Geolocation in mongodb Geolocation in mongodb Presentation Transcript

  • GEOLOCATION IN MONGODB { name: ‘Shashank Tiwari’, web: ‘shanky.org’}Wednesday, November 28, 12
  • WHO AM I? Entrepreneur, developer, author Most recent book: Professional NoSQL (Wiley, 2011) Co-founder :Wednesday, November 28, 12
  • DEGREES OF MEASURE Latitude LongitudeWednesday, November 28, 12
  • DEGREE OF LONGITUDEWednesday, November 28, 12
  • GEO IN MONGO Is a world in 2DWednesday, November 28, 12
  • MONGO DOC WITH LOC { loc : [37.407202, -122.10716] } { loc : { x: 37.407202, y: -122.10716} } { loc : { lat: 37.407202, lon: -122.10716} }Wednesday, November 28, 12
  • INDEX db.places.ensureIndex( { loc : "2d" } ) 1 geospatial index per collectionWednesday, November 28, 12
  • INDEX RANGE db.places.ensureIndex( { loc : "2d" } , { min : -500 , max : 500 } )Wednesday, November 28, 12
  • INDEX PRECISION db.places.ensureIndex( { loc : "2d" } , { bits : 26 } ) Geo-hash precision of 26bits ~ 2 feetWednesday, November 28, 12
  • EXACT QUERIES > db.places.find({ loc : [ 37.407202, -122.10716 ]}); { "_id" : ObjectId("50b69e66e6945f62a019f3a4"), "name" : "San Antonio Caltrain", "loc" : [ 37.407202, -122.10716 ] }Wednesday, November 28, 12
  • EXPLAIN QUERY PLAN db.places.find({ loc : [ 37.407202, -122.10716 ]}).explain();Wednesday, November 28, 12
  • COMPOUND INDEX db.places.ensureIndex( { loc : "2d", name : 1 } )Wednesday, November 28, 12
  • NEAR QUERY db.places.find({ loc : { $near : [ 37.407202, -122.10716 ]}}); Returns points sorted by distanceWednesday, November 28, 12
  • 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, November 28, 12
  • GEONEAR QUERY db.runCommand({ geoNear : "places", near : [37.407202, -122.10716], num : 5 }); also gives the distanceWednesday, November 28, 12
  • MORE WITH GEONEAR db.runCommand({ geoNear : "places", near : [37.407202, -122.10716], num : 5, type : “DO” }); parameters: near, num, maxDistance, queryWednesday, November 28, 12
  • WITHIN A BOX db.places.find({ loc : { $within : { $box : [[39.589821, -122.438831], [37.485200, -122.228438]] }}});Wednesday, November 28, 12
  • WITHIN A CIRCLE db.places.find({ loc : { $within : { $center : [[39.589821, -122.438831], 10] }}});Wednesday, November 28, 12
  • WITHIN A POLYGON Polygon shapes currently cannot be indexedWednesday, November 28, 12
  • SPHERICAL SUPPORT geoNear -- spherical : true $nearSphere $centerSphere Order is important, very important -- longitude, latitudeWednesday, November 28, 12
  • MULTI LOCATIONS db.places.insert({ placesVisitedToday : [ { name : "San Antonio Caltrain", loc : [37.407202, -122.10716] }, { name : "Kixeye", loc : [37.7906672, -122.403256] } ] })Wednesday, November 28, 12
  • QUERY MULTI LOC db.places.ensureIndex( { " placesVisitedToday.loc " : "2d"} ) use uniqueDocs : true to get unique documentsWednesday, November 28, 12
  • Wednesday, November 28, 12
  • Wednesday, November 28, 12
  • NEXT TALK More details and some about GIS too! SV MongoDB User Group @ Palo Alto -- January MeetupWednesday, November 28, 12
  • THANKS More questions? web: shanky.org | twitter : @tshanky Want to join the alpha program? doaround.comWednesday, November 28, 12