Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8974

$geoNear alias causes error when using with 2d index

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.0
    • Affects Version/s: 2.4.0-rc3
    • Component/s: Geo
    • None
    • ALL

      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.

            Assignee:
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Reporter:
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: