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

geoNear should not allow $natural

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 2.6.3
    • Fix Version/s: 2.7.3
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      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 ] } }

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: