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

Support many accumulators in aggregation framework as expressions

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.7
    • Affects Version/s: 2.4.3
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Fully Compatible
    • Quint Iteration 7, QuInt 8 08/28/15

      Make the following accumulators available as expressions: $stdDevSamp, $stdDevPop, $avg, $min, $max, and $sum.

      As expressions, available in the $project stage, these operators can take either:

      • A single argument: <accumulator> : <arg>
      • Multiple arguments: <accumulator> : [ <arg1>, <arg2>, ... ]
      Single Argument: <arg>

      If the argument is an array, the accumulator operates on the elements of the array to return a single value. If the argument is not an array, the accumulator operates on the single argument.

      Multiple arguments: [ <arg1>, <arg2>, ... ]

      The accumulator operates on the arguments to return a single value.

      If any of the argments is an array, the accumulator does not traverse into the array elements.

      Non-numerical arguments

      When used as part of the $project stage, $sum, $avg, $stdDevSamp, and $stdDevPop ignore non-numerical arguments.

      Original request:
      {'$group': {
          '_id': {
              'grp_0': '$ses.usr',
              'grp_1': '$ses._id'
          },
          'agg_0': {'$sum': {'$subtract': [
              {'$cond': [{'$lt': ['$ses.e', E]},
                         '$ses.e',
                         E]},
              {'$cond': [{'$gt': ['$ses.s', S]},
                         '$ses.s',
                         S]}
              ]}
           }
      }}
      

      you can write:

      {'$group':
        {
          '_id': {
            'grp_0': '$ses.usr',
            'grp_1': '$ses._id'
          },
          'agg_0': {'$sum': {'$subtract': [
            {'$min': ['$ses.e', E]}, 
            {'$max': ['$ses.s', S]}
           ]}
          }
        }
      }
      

            Assignee:
            james.cohan James Cohan
            Reporter:
            schou@barracuda.com Samuel Chou
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: