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

Incorrect null equality check for objects inside arrays

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 6.0.14
    • Component/s: None
    • Labels:
      None
    • ALL
    • Hide

      The description can be used as steps to reproduce.

      Show
      The description can be used as steps to reproduce.

      Null equality seems to evaluate always to true when comparing a field of a document inside an array.

      Concretely, Given this dataset of 3 elements

      [
        {
          "xs": [
            {
              "name": "a"
            }
          ]
        },
        {
          "xs": [
            {
              "name": null
            }
          ]
        },
        {
          "xs": [
            {}
          ]
        }
      ] 

      When performing the query 

      db.collection.find({
        "xs.0.name": {
          $eq: null
        }
      }) 

      we would expect to get the 2nd and 3rd result, but the actual result is that all documents are returned.

       

      The following returns the expected results:

      db.collection.find({
        "$or": [
          {
            "xs.0.name": {
              $exists: false
            }
          },
          {
            "xs.0.name": {
              $type: "null"
            }
          }
        ]
      })

       

       

            Assignee:
            edwin.zhou@mongodb.com Edwin Zhou
            Reporter:
            apostolos.livanios@navenio.com Apostolos Livanios
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: