Skip to content

Instantly share code, notes, and snippets.

@esedor
Last active August 29, 2015 13:57
Show Gist options
  • Save esedor/9459580 to your computer and use it in GitHub Desktop.
Save esedor/9459580 to your computer and use it in GitHub Desktop.
// Finding a "start" point
> use proximity
switched to db proximity
> doc
{
"loc" : {
"type" : "LineString",
"coordinates" : [
[
40,
5
],
[
41,
6
]
]
},
"name" : "Eric",
"route" : 1,
"leg" : 1,
"tags" : [
"start"
]
}
> db.routes.insert(doc)
> db.routes.ensureIndex({ "loc" : "2dsphere", "tags" : 1 })
> db.routes.find({ "loc" : { "$near" : { "$geometry" : { type : "Point" , "coordinates" : [ 40.0001 , 5.0001 ] } , "$maxDistance" : 100 } }, "tags": "start" } )
{ "_id" : ObjectId("531d40a44ef44728e43ed2db"),
"loc" : { "type" : "LineString", "coordinates" : [ [ 40, 5 ], [ 41, 6 ] ] },
"name" : "Eric",
"route" : 1,
"leg" : 1,
"tags" : [ "start" ] }
// Finding a "route" in order
db.routes.ensureIndex({route": 1, "leg": 1})
> db.routes.find({"route": 1}).sort({"leg": 1})
{ "_id" : ObjectId("531d42f74ef44728e43ed2df"), "loc" : { "type" : "LineString", "coordinates" : [ [ 40, 5 ], [ 41, 6 ] ] }, "name" : "Eric", "route" : 1, "leg" : 1, "tags" : [ { "name" : "start", "description" : "hello" } ] }
@monking
Copy link

monking commented Mar 10, 2014

Thanks very much for sharing this, Eric. I'm tempted to port the data and test it now, but I have to get some sleep on this bus back to L.A. I'll put it to use in the afternoon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment