Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Reduce

Index

Properties

Properties

$reduce: { input: ArrayExpression<any>; initialValue: any; in: any }

Applies an expression to each element in an array and combines them into a single value.

version

3.4

see

https://docs.mongodb.com/manual/reference/operator/aggregation/reduce/#mongodb-expression-exp.-reduce

Type declaration

  • input: ArrayExpression<any>

    Can be any valid expression that resolves to an array. For more information on expressions, see Expressions.

    If the argument resolves to a value of null or refers to a missing field, $reduce returns null.

    If the argument does not resolve to an array or null nor refers to a missing field, $reduce returns an error.

  • initialValue: any

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

  • in: any

    A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left.

    During evaluation of the in expression, two variables will be available:

    • value is the variable that represents the cumulative value of the expression.
    • this is the variable that refers to the element being processed.

Generated using TypeDoc