Skip to content

Instantly share code, notes, and snippets.

@monking
Forked from esedor/gist:9459580
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monking/9460530 to your computer and use it in GitHub Desktop.
Save monking/9460530 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" } ] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment