$elemMatch not matching all elements

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: 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
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      $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
            Reporter:
            Nikita Mikhaylov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: