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

arrayEq/anyEq behave incorrectly with mongo shell types

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.3.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • Show
      Repro: arrayEqTest.js
    • Execution Team 2022-12-12, Execution Team 2022-11-28, Execution Team 2022-12-26

      In jstests/aggregation/extras/utils.js.

      The function anyEq (and in turn arrayEq) considers mongo shell types (NumberLong/NumberInt/ObjectId, ...) elements as equal. This is caused by these having all properties as inherited, so no actual comparisons are made for the values within documentEq that arrayEq/anyEq uses to compare objects.

       

      [js_test:arrayEqTest] dl NumberLong(4) dr NumberLong(5)
      [js_test:arrayEqTest] property in dl floatApprox is own false
      [js_test:arrayEqTest] property in dl top is own false
      [js_test:arrayEqTest] property in dl bottom is own false
      [js_test:arrayEqTest] property in dl exactValueString is own false
      [js_test:arrayEqTest] property in dl tojson is own false
      [js_test:arrayEqTest] documentEq: these are equal: NumberLong(4) == NumberLong(5)
      [js_test:arrayEqTest] dl { "a" : NumberInt(1) } dr { "a" : NumberInt(1) }
      [js_test:arrayEqTest] property in dl a is own true
      [js_test:arrayEqTest] dl NumberInt(1) dr NumberInt(1)
      [js_test:arrayEqTest] property in dl tojson is own false
      [js_test:arrayEqTest] documentEq: these are equal: NumberInt(1) == NumberInt(1)
      [js_test:arrayEqTest] anyEq: these are equal: NumberInt(1) == NumberInt(1)
      [js_test:arrayEqTest] documentEq: these are equal: { "a" : NumberInt(1) } == { "a" : NumberInt(1) }
      [js_test:arrayEqTest] anyEq: these are equal: { "a" : NumberInt(1) } == { "a" : NumberInt(1) }
      [js_test:arrayEqTest] dl { "b" : NumberInt(2) } dr { "b" : NumberInt(4) }
      [js_test:arrayEqTest] property in dl b is own true
      [js_test:arrayEqTest] dl NumberInt(2) dr NumberInt(4)
      [js_test:arrayEqTest] property in dl tojson is own false
      [js_test:arrayEqTest] documentEq: these are equal: NumberInt(2) == NumberInt(4)
      [js_test:arrayEqTest] anyEq: these are equal: NumberInt(2) == NumberInt(4)
      [js_test:arrayEqTest] documentEq: these are equal: { "b" : NumberInt(2) } == { "b" : NumberInt(4) }
      [js_test:arrayEqTest] anyEq: these are equal: { "b" : NumberInt(2) } == { "b" : NumberInt(4) }
      [js_test:arrayEqTest] 2022-08-10T16:33:46.733Z assert failed : arrayEq not working as expected.
      

        1. arrayEqTest.js
          0.9 kB
          Yujin Kang Park

            Assignee:
            yujin.kang@mongodb.com Yujin Kang Park
            Reporter:
            yujin.kang@mongodb.com Yujin Kang Park
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: