Standard Use Cases of Aggregations

Count Submissions

{ filterCriteria: [], lookUpPaths: [], modificationTime: '2021-01-19T13:02:42.998+00:00', aggregations: [ { '$group': { _id: '', count: { '$sum': 1 } } }, { '$project': { _id: 0, result: '$count' } } ] }

Count submissions (with a multiple selection question in the DC)

You should use this code if you want to count the submissions to a DC and the DC has at least one multiple selection question. Because otherwise when filtering submissions will be counted more than once.

Be carefull when you add filters or grouping which needs lookups to other collection references with multi select enabled. In this case the lookup results to one result per multi selected entry. E. g. if you have a selection of 3 categories, the submission will be 3 times in the result for each category. In this case you have to work with grouping to have unique results to count

{ filterCriteria: [], lookUpPaths: [], modificationTime: '2021-03-15T16:18:53.905+00:00', aggregations: [ { '$group': { _id: '$code' } }, { '$count': 'result' } ] }

Sum of number field

{ filterCriteria: [], lookUpPaths: [], modificationTime: '2021-02-23T06:23:01.675+00:00', aggregations: [ { '$group': { _id: '', result: { '$sum': '$answers.beneficiariesTotal' } } } ] }

Count submission by selection field

Sum of a number field and group by a selection field

Sum of a number field and group by 2 selection field.

Â