|
| 1 | +.. _aggregation-options: |
| 2 | + |
| 3 | +=================== |
| 4 | +Aggregation Options |
| 5 | +=================== |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 1 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +Dragging a field onto an :guilabel:`aggregation` |
| 16 | +:ref:`encoding channel <encoding-channels>` allows you to use an |
| 17 | +:manual:`aggregation pipeline operator </reference/operator/aggregation/>` |
| 18 | +on that field. |
| 19 | + |
| 20 | +The aggregation pipeline operators available in the chart |
| 21 | +builder change based on the :manual:`data type </reference/bson-types/>` |
| 22 | +of the selected field. MongoDB Charts categorizes the field data type |
| 23 | +as either a ``number``, ``string``, or ``date`` and displays |
| 24 | +appropriate aggregation options accordingly. |
| 25 | + |
| 26 | +The following tables list the available aggregation options for each |
| 27 | +data type: |
| 28 | + |
| 29 | +Numbers |
| 30 | +------- |
| 31 | + |
| 32 | +.. list-table:: |
| 33 | + :header-rows: 1 |
| 34 | + :stub-columns: 1 |
| 35 | + :widths: 20 40 40 |
| 36 | + |
| 37 | + * - Aggregation Option |
| 38 | + - Description |
| 39 | + - Pipeline Operation |
| 40 | + |
| 41 | + * - ``sum`` |
| 42 | + - Sums all values in the field. |
| 43 | + - :manual:`$sum </reference/operator/aggregation/sum/>` |
| 44 | + |
| 45 | + * - ``count`` |
| 46 | + - Counts the number of documents with a value in the field. |
| 47 | + - :manual:`$count </reference/operator/aggregation/count/>` |
| 48 | + |
| 49 | + * - ``distinct`` |
| 50 | + - Counts the number of unique values in the field. |
| 51 | + - Applies |
| 52 | + :manual:`$addToSet </reference/operator/aggregation/addToSet/>` |
| 53 | + and counts the number of items in the result set with |
| 54 | + :manual:`$size </reference/operator/aggregation/size/>`. |
| 55 | + |
| 56 | + * - ``mean`` |
| 57 | + - Averages all values in the field. |
| 58 | + - :manual:`$avg </reference/operator/aggregation/avg/>` |
| 59 | + |
| 60 | + * - ``min`` |
| 61 | + - Returns the minimum value in the field. |
| 62 | + - :manual:`$min </reference/operator/aggregation/min/>` |
| 63 | + |
| 64 | + * - ``max`` |
| 65 | + - Returns the minimum value in the field. |
| 66 | + - :manual:`$max </reference/operator/aggregation/max/>` |
| 67 | + |
| 68 | + * - ``variance`` |
| 69 | + - Calculates the sample variance of values in the field. |
| 70 | + - Applies |
| 71 | + :manual:`$stdDevSamp </reference/operator/aggregation/stdDevSamp/>` |
| 72 | + and raises the result to the 2nd power with |
| 73 | + :manual:`$pow </reference/operator/aggregation/pow/>`. |
| 74 | + |
| 75 | + * - ``variancep`` |
| 76 | + - Calculates the population variance of values in the field. |
| 77 | + - Applies |
| 78 | + :manual:`$stdDevPop </reference/operator/aggregation/stdDevPop/>` |
| 79 | + and raises the result to the 2nd power with |
| 80 | + :manual:`$pow </reference/operator/aggregation/pow/>`. |
| 81 | + |
| 82 | + * - ``stdev`` |
| 83 | + - Calculates the sample standard deviation of values in the field. |
| 84 | + - :manual:`$stdDevSamp </reference/operator/aggregation/stdDevSamp/>` |
| 85 | + |
| 86 | + * - ``stdevp`` |
| 87 | + - Calculates the population standard deviation of values in the |
| 88 | + field. |
| 89 | + - :manual:`$stdDevPop </reference/operator/aggregation/stdDevPop/>` |
| 90 | + |
| 91 | +Strings and Dates |
| 92 | +----------------- |
| 93 | + |
| 94 | +.. list-table:: |
| 95 | + :header-rows: 1 |
| 96 | + :stub-columns: 1 |
| 97 | + :widths: 20 40 40 |
| 98 | + |
| 99 | + * - Aggregation Option |
| 100 | + - Description |
| 101 | + - Pipeline Operation |
| 102 | + |
| 103 | + * - ``count`` |
| 104 | + - Counts the number of documents with a value in the field. |
| 105 | + - :manual:`$count </reference/operator/aggregation/count/>` |
| 106 | + |
| 107 | + * - ``distinct`` |
| 108 | + - Counts the number of unique values in the field. |
| 109 | + - Applies the |
| 110 | + :manual:`$addToSet </reference/operator/aggregation/addToSet/>` |
| 111 | + operator and counts the number of items in the result set with |
| 112 | + :manual:`$size </reference/operator/aggregation/size/>`. |
0 commit comments