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

Support numeric arrays as input to $add in aggregation's $project

    • Fully Compatible
    • Quint Iteration 7

      The $add expression (as used in $project aggregation operator) supports the ability to have an explicit array of numbers to sum be specified, such as:

      {$project: {total: {$add: [1, 2, 3]}}}

      However, when same array numeric value is provided as an input, the addition/summation does not occur:

      c.save({a: [1, 2, 3]});
      assert.eq(c.aggregate({$project: {total: {$add: "$a"}}}).result[0].total, 6); // Fails
      

      This summation is entirely contained within the document. Today, doing this requires an $unwind followed by a $group. However {$group: {_id: "$_id"}} does not stream and can easily hit the 16MB limit on large collections. Furthermore, it's a shame to use $unwind/{$group: {_id: "$_id"}}, as it's just a verbose projection.

      The proposal is to make the above the test case pass.

      This would need documentation updates.

            Assignee:
            james.cohan James Cohan
            Reporter:
            oleg@evergage.com Oleg Rekutin
            Votes:
            2 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: