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

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

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.4.6
    • Fix Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Sprint:
      Quint Iteration 7

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: