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

The $add aggregation expression is not always commutative

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 6.0.0-rc8
    • Component/s: None
    • None
    • Query Optimization
    • ALL
    • Hide

      db.test.drop();

      db.test.insert({_id: 1, x: new Date()});

      // Returns a result.
      db.test.aggregate([{$project: {a: {$add: [null, new Date(), "$x"]}}}])

      // Fails with error code 16612, "only one date allowed in an $add expression".
      db.test.aggregate([{$project: {a: {$add: [new Date(), "$x", null]}}}])

      Show
      db.test.drop(); db.test.insert({_id: 1, x: new Date()}); // Returns a result. db.test.aggregate([{$project: {a: {$add: [null, new Date(), "$x"] }}}]) // Fails with error code 16612, "only one date allowed in an $add expression". db.test.aggregate([{$project: {a: {$add: [new Date(), "$x", null] }}}])
    • 53

      The $add expression is defined as being commutative, which is not true when a null value exists in the list being summed.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            james.wahlin@mongodb.com James Wahlin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: