Description
$geoNear is an alias for $near and should work for both 2d and 2dsphere indexes.
It throws and error in a 2d index.
Steps to reproduce
db.places.drop()
|
db.places.insert({loc: [10, 10], name: "restaurant"})
|
db.places.ensureIndex({loc: "2d"})
|
|
// this works
|
var result = db.places.find( { loc : { $near : [ 10 , 5 ] , $maxDistance : 10 } } )
|
assert(result.count() == 1)
|
|
// throws uassert 13464
|
var result = db.places.find( { loc : { $geoNear : [ 10 , 5 ] , $maxDistance : 10 } } )
|
assert(result.count() == 1)
|
Reason
In src/mongo/db/geo/2d.cpp line 2301, it is assumed that all "near" operators start with the prefix $near. It is then checked, whether the following characters are "\0" or "Sphere". This fails for "$geoNear".
An explicit switch/case for the strings "$near", "$nearSphere", "$geoNear" would be better here. Or change line 2303 to:
if ( (suffix[0] == '\0') || (strcmp(suffix, "ear") == 0) ) {
|
But an explicit strcmp for all operator names is cleaner.
|