$reduce
The `$reduce` operator applies an expression to each element in an array and combines them into a single value.
Syntax
{
$reduce: {
input: "<array>",
initialValue: "<expression>",
in: "<expression>"
}
}
Parameters
input
stringrequiredAn expression that resolves to an array.
initialValue
stringrequiredThe initial cumulative value set before in is applied to the first element of the input array.
in
stringrequiredAn expression that is applied to each element in the input array. References the cumulative value using $$value and the current element using $$this.