Skip to content

Instantly share code, notes, and snippets.

@curtkim
Created August 10, 2017 08:04
Show Gist options
  • Save curtkim/ca87db8f1b666ec9955ec777fa626da9 to your computer and use it in GitHub Desktop.
Save curtkim/ca87db8f1b666ec9955ec777fa626da9 to your computer and use it in GitHub Desktop.
mongo geospatial
db.gates.insert(
{
boundary : { type: "Polygon", coordinates: [ [ [ 127, 37] , [127.1 , 37] , [127 , 37.1] , [ 127, 37] ] ] },
gate : {type: "Point", coordinates:[127, 37] }
}
)
db.gates.createIndex( { boundary : "2dsphere" } )
db.gates.find( { boundary :
{ $geoWithin :
{ $geometry :
{ type : "Polygon" ,
coordinates : [ [ [ 127, 37 ] ,
[ 127.1, 37 ] ,
[ 127.1, 37.1 ] ,
[ 127, 37.1 ],
[ 127, 37 ] ] ]
} } } } )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment