$avg
$avg
operator helps you in calculating average of some values in an expression. You can use this in any Expression Object
Syntax
{
"$avg":[<expr>, <expr> ,....]
}
Properties
Field
Description
Required
<expr>
The <expr>
expression can be any valid expression as long as it resolves to a number.
It can also be a Magical Autocomplete.
true
Returns
float
- The result of $avg operation
Examples
Basic example
{
"$avg": [1,2,3,4,5]
}
The above expression returns 3.0
With Nested Expressions
{
"$avg": [
1,
2,
{ "$add" : [1,2] },
{ "$pow" : [2,2] },
5
]
}
The above expression calculates the nested expressions, return 3 and 4 respectively in its place and then the outer $avg
expression returns 3.0 overall.
With Magical Autocomplete
Let's say we have declared a variable temp
of type array in our API flow, which has a value of
[ 2,4,8,2 ] currently.
{
"$avg":"$.variables.temp"
}
The above expression would resolve to a result of 4
Last updated