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

geoNear should not allow $natural

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.7.3
    • Affects Version/s: 2.6.3
    • Component/s: Querying
    • Labels:
      None
    • ALL
    • Hide
      > t.drop()
      > t.ensureIndex({a: "2dsphere"})
      > t.save({a: {type: "Point", coordinates: [3, 4]}})
      > t.save({a: {type: "Point", coordinates: [1, 2]}})
      > t.find({a: {$near: {$geometry: {type: "Point", coordinates: [1, 2]}}}})
      { "_id" : ObjectId("53ac81a37616f382be9e6fdb"), "a" : { "type" : "Point", "coordinates" : [ 1, 2 ] } }
      { "_id" : ObjectId("53ac81a07616f382be9e6fda"), "a" : { "type" : "Point", "coordinates" : [ 3, 4 ] } }
      > t.find({a: {$near: {$geometry: {type: "Point", coordinates: [1, 2]}}}}).hint({$natural: 1})
      { "_id" : ObjectId("53ac81a07616f382be9e6fda"), "a" : { "type" : "Point", "coordinates" : [ 3, 4 ] } }
      { "_id" : ObjectId("53ac81a37616f382be9e6fdb"), "a" : { "type" : "Point", "coordinates" : [ 1, 2 ] } }
      > t.find({a: {$near: {$geometry: {type: "Point", coordinates: [1, 2]}}}}).sort({$natural: 1})
      { "_id" : ObjectId("53ac81a07616f382be9e6fda"), "a" : { "type" : "Point", "coordinates" : [ 3, 4 ] } }
      { "_id" : ObjectId("53ac81a37616f382be9e6fdb"), "a" : { "type" : "Point", "coordinates" : [ 1, 2 ] } }
      
      Show
      > t.drop() > t.ensureIndex({a: "2dsphere" }) > t.save({a: {type: "Point" , coordinates: [3, 4]}}) > t.save({a: {type: "Point" , coordinates: [1, 2]}}) > t.find({a: {$near: {$geometry: {type: "Point" , coordinates: [1, 2]}}}}) { "_id" : ObjectId( "53ac81a37616f382be9e6fdb" ), "a" : { "type" : "Point" , "coordinates" : [ 1, 2 ] } } { "_id" : ObjectId( "53ac81a07616f382be9e6fda" ), "a" : { "type" : "Point" , "coordinates" : [ 3, 4 ] } } > t.find({a: {$near: {$geometry: {type: "Point" , coordinates: [1, 2]}}}}).hint({$natural: 1}) { "_id" : ObjectId( "53ac81a07616f382be9e6fda" ), "a" : { "type" : "Point" , "coordinates" : [ 3, 4 ] } } { "_id" : ObjectId( "53ac81a37616f382be9e6fdb" ), "a" : { "type" : "Point" , "coordinates" : [ 1, 2 ] } } > t.find({a: {$near: {$geometry: {type: "Point" , coordinates: [1, 2]}}}}).sort({$natural: 1}) { "_id" : ObjectId( "53ac81a07616f382be9e6fda" ), "a" : { "type" : "Point" , "coordinates" : [ 3, 4 ] } } { "_id" : ObjectId( "53ac81a37616f382be9e6fdb" ), "a" : { "type" : "Point" , "coordinates" : [ 1, 2 ] } }

      Geo $near queries should always return results sorted by increasing distance from the query point. However, we handle $natural hint or sort before checking if there is a $near query. The result is that we end up doing a collection scan, hence returning results in the wrong order (see "Steps to Reproduce" for details).

      A useful error is returned if $text is combined with $natural hint or $natural sort. We should do the same for geoNear.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: