[SERVER-8974] $geoNear alias causes error when using with 2d index Created: 13/Mar/13  Updated: 11/Jul/16  Resolved: 15/Mar/13

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: 2.4.0-rc3
Fix Version/s: 2.5.0

Type: Bug Priority: Major - P3
Reporter: Thomas Rueckstiess Assignee: Thomas Rueckstiess
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   
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.



 Comments   
Comment by auto [ 15/Mar/13 ]

Author:

{u'date': u'2013-03-13T21:12:52Z', u'name': u'Thomas Rueckstiess', u'email': u'thomas@10gen.com'}

Message: SERVER-8974 $geoNear alias for $near now works with 2d indexes. Was throwing uassert 13464 before.

Signed-off-by: Ian Whalen <ian.whalen@gmail.com>
Branch: master
https://github.com/mongodb/mongo/commit/2bab9b2747e97d6835310816b09b3b259735061a

Generated at Thu Feb 08 03:18:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.