$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

inputstringrequired

An expression that resolves to an array.

initialValuestringrequired

The initial cumulative value set before in is applied to the first element of the input array.

instringrequired

An expression that is applied to each element in the input array. References the cumulative value using $$value and the current element using $$this.