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

$elemMatch not matching all elements

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.4.4
    • Component/s: Aggregation Framework
    • None
    • ALL
    • Hide
      > db.table.insert({_id: 1, foo: [{"bar": {a: 1, b : 2}}]})
      WriteResult({ "nInserted" : 1 })
      > db.table.findOne({foo: {$elemMatch: {"bar" : {a:1, b:2}}}})
      {
              "_id" : 1,
              "foo" : [
                      {
                              "bar" : {
                                      "a" : 1,
                                      "b" : 2
                              }
                      }
              ]
      }
      > db.table.findOne({foo: {$elemMatch: {"bar" : {b:2, a:1}}}})
      null
      Show
      > db.table.insert({_id: 1, foo: [{ "bar" : {a: 1, b : 2}}]}) WriteResult({ "nInserted" : 1 }) > db.table.findOne({foo: {$elemMatch: { "bar" : {a:1, b:2}}}}) { "_id" : 1, "foo" : [ { "bar" : { "a" : 1, "b" : 2 } } ] } > db.table.findOne({foo: {$elemMatch: { "bar" : {b:2, a:1}}}}) null

      $elemmatch operator seems to be faulty when matching complex objects, the order of keys inside the object determines whether the object matches the query.

      Tested the behaviour on 3.6.8 and 4.4.4

            Assignee:
            eric.sedor@mongodb.com Eric Sedor
            Reporter:
            shessmaster12@gmail.com Nikita Mikhaylov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: