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

Certain queries against compound 2d/text indexes are incorrectly covered, return incorrect results

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.4.11, 3.6.0-rc1
    • Affects Version/s: 3.0.6
    • Component/s: Querying
    • Fully Compatible
    • ALL
    • v3.4, v3.2
    • Hide
      > db.foo.drop()
      true
      > db.foo.insert({a: 1, "location" : [ -117.15, 32.88 ]})
      WriteResult({ "nInserted" : 1 })
      > db.foo.insert({a: 2, "location" : [ -117.15, 32.88 ]})
      WriteResult({ "nInserted" : 1 })
      > db.foo.insert({a: 3, "location" : [ -117.15, 32.88 ]})
      WriteResult({ "nInserted" : 1 })
      > db.foo.ensureIndex({location: "2d"})
      {
              "createdCollectionAutomatically" : false,
              "numIndexesBefore" : 1,
              "numIndexesAfter" : 2,
              "ok" : 1
      }
      

      In the query below, we request documents where b exists. As expected, we get 0 results.

      > db.foo.find({location: { $nearSphere: [ -117.2684194, 33.1029176 ], $maxDistance: 0.02526017985248055 }, b: { $exists: true}})
      # no results (expected)
      

      When an index is added on (location, b), all documents are returned when $exists: true is set for b, which is incorrect.

      > db.foo.ensureIndex({location: "2d", b: 1})
      {
              "createdCollectionAutomatically" : false,
              "numIndexesBefore" : 2,
              "numIndexesAfter" : 3,
              "ok" : 1
      }
      > db.foo.find({location: { $nearSphere: [ -117.2684194, 33.1029176 ], $maxDistance: 0.02526017985248055 }, b: { $exists: true}}).hint("location_2d_b_1")
      { "_id" : ObjectId("562524f65a47d987934ec69b"), "a" : 1, "location" : [ -117.15, 32.88 ] }
      { "_id" : ObjectId("562524fb5a47d987934ec69c"), "a" : 2, "location" : [ -117.15, 32.88 ] }
      { "_id" : ObjectId("562525005a47d987934ec69d"), "a" : 3, "location" : [ -117.15, 32.88 ] }
      
      Show
      > db.foo.drop() true > db.foo.insert({a: 1, "location" : [ -117.15, 32.88 ]}) WriteResult({ "nInserted" : 1 }) > db.foo.insert({a: 2, "location" : [ -117.15, 32.88 ]}) WriteResult({ "nInserted" : 1 }) > db.foo.insert({a: 3, "location" : [ -117.15, 32.88 ]}) WriteResult({ "nInserted" : 1 }) > db.foo.ensureIndex({location: "2d"}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } In the query below, we request documents where b exists. As expected, we get 0 results. > db.foo.find({location: { $nearSphere: [ -117.2684194, 33.1029176 ], $maxDistance: 0.02526017985248055 }, b: { $exists: true}}) # no results (expected) When an index is added on (location, b), all documents are returned when $exists: true is set for b, which is incorrect. > db.foo.ensureIndex({location: "2d", b: 1}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 2, "numIndexesAfter" : 3, "ok" : 1 } > db.foo.find({location: { $nearSphere: [ -117.2684194, 33.1029176 ], $maxDistance: 0.02526017985248055 }, b: { $exists: true}}).hint("location_2d_b_1") { "_id" : ObjectId("562524f65a47d987934ec69b"), "a" : 1, "location" : [ -117.15, 32.88 ] } { "_id" : ObjectId("562524fb5a47d987934ec69c"), "a" : 2, "location" : [ -117.15, 32.88 ] } { "_id" : ObjectId("562525005a47d987934ec69d"), "a" : 3, "location" : [ -117.15, 32.88 ] }
    • QuInt C (11/23/15), Query 2017-10-23

      In Mongo 3.0.6, compound 2d indexes do not filter results correctly when an $exists operator is used on the second key. This can cause incorrect data to be returned depending on which index is selected.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            tredman@fb.com Travis Redman
            Votes:
            1 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: