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

Using a $elemMatch with two $eq queries returns incorrect results

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.0
    • Component/s: Shell
    • None
    • Environment:
      Windows Server 2008R2, MongoChef
    • ALL
    • Hide

      doc:

      { "STags" : [ "OD:52_domain.com", "OL:92_mlbx" ] }
      { "STags" : [ "OD:49_domain.com", "OL:92_mlbx" ] }
      

      Queries:

      db.test.find({"STags" : { $elemMatch : { $eq : "OD:52_domain.com", $eq : "OL:92_mlbx"} }})
      db.test.find({"STags" : { $elemMatch : { $eq : "OD:sdsfsfd", $eq : "OL:92_mlbx"} }})
      

      Both queries return two documents. even though 2nd query specifies a values that does NOT exist in any document.

      Replacing the $elemMath by a $and does not exhibit the same behaviour and returns the correct results.

      Show
      doc: { "STags" : [ "OD:52_domain.com", "OL:92_mlbx" ] } { "STags" : [ "OD:49_domain.com", "OL:92_mlbx" ] } Queries: db.test.find({"STags" : { $elemMatch : { $eq : "OD:52_domain.com", $eq : "OL:92_mlbx"} }}) db.test.find({"STags" : { $elemMatch : { $eq : "OD:sdsfsfd", $eq : "OL:92_mlbx"} }}) Both queries return two documents. even though 2nd query specifies a values that does NOT exist in any document. Replacing the $elemMath by a $and does not exhibit the same behaviour and returns the correct results.
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Using a $elemMatch with two $eq queries is returning all documents that only one of the $eq. And which one is matched depends on the order of the $eq in the statement.

            Assignee:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Reporter:
            gnarlyrides@gmail.com Jason Mccullough
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: