Last active
August 29, 2015 13:57
-
-
Save esedor/9459580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
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.