Skip to main content

$avg

The $avg operator returns the average (mean) of all numeric input values.

Input

  • An array of numeric values to average (at least one value required)

Output

  • The average of all input values

Examples

Average of Multiple Values

{
  "$avg": [
    1,
    2,
    3,
    4
  ]
}
Result: 2.5

Average of Field Values

{
  "$avg": [
    {
      "$input": "score1"
    },
    {
      "$input": "score2"
    },
    {
      "$input": "score3"
    }
  ]
}
Result: The average of score1, score2, and score3 fields

Single Value

{
  "$avg": [
    5
  ]
}
Result: 5