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

$elemMatch not matching all elements

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 4.4.4
    • 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

    Description

      $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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: