Tuesday, 6 August 2013

what is the right way to query a 2dsphere index to get results sorted by nearest-first with max_distance?

what is the right way to query a 2dsphere index to get results sorted by
nearest-first with max_distance?

> version()
version: 2.0.4
can't find special index: 2d for: { location: { $near: { $geometry: {
type: "Point", coordinates: [ 0.1, 0.1 ] } }, $maxDistance: 5000.0 } }
> version()
version: 2.0.4
can't find special index: 2d for: { location: { $near: { $geometry: {
type: "Point", coordinates: [ 0.1, 0.1 ] } }, $maxDistance: 5000.0 } }
> db.syncsnapshotsphere.find()
{ "_id" : "naga", "location" : { "type" : "Point", "coordinates" : [ 0.1,
0.1 ] }, "timestamp" : 1375778757.568005 }
{ "_id" : "nagb", "location" : { "type" : "Point", "coordinates" : [ 0.2,
0.2 ] }, "timestamp" : 1375778792.552187 }
{ "_id" : "nagc", "location" : { "type" : "Point", "coordinates" : [ 0.3,
0.3 ] }, "timestamp" : 1375778803.047879 }
{ "_id" : "nagd", "location" : { "type" : "Point", "coordinates" : [ 0.4,
0.4 ] }, "timestamp" : 1375778814.088595 }
> db.syncsnapshotsphere.find({location: {$near: {$geometry: {type:
"Point", coordinates: [0.1,0.1]}}, $maxDistance: 5000}})
error: {
"$err" : "can't find special index: 2d for: { location: { $near: {
$geometry: { type: \"Point\", coordinates: [ 0.1, 0.1 ] } },
$maxDistance: 5000.0 } }",
"code" : 13038
}
The weird looking "cant find special index..." soon after the second line
"version..." is actually the output... I don't know why.
I am trying to figure out why I get the error saying that it is trying to
find a 2d index where as a 2dsphere index already exists on the location
field... All help is appreciated.
> db.syncsnapshotsphere.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "logging_stuff.syncsnapshotsphere",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"location" : "2dsphere"
},
"ns" : "logging_stuff.syncsnapshotsphere",
"name" : "location_2dsphere",
"background" : false,
"dropDups" : false
}
]
>

No comments:

Post a Comment