Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Accumulator

Index

Properties

Properties

$accumulator: { init: CodeExpression; initArgs?: ArrayExpression<any>; accumulate: CodeExpression; accumulateArgs: ArrayExpression<any>; merge: CodeExpression; finalize?: CodeExpression; lang: "js" }

Defines a custom accumulator operator. Accumulators are operators that maintain their state (e.g. totals, maximums, minimums, and related data) as documents progress through the pipeline. Use the $accumulator operator to execute your own JavaScript functions to implement behavior not supported by the MongoDB Query Language. See also $function.

version

4.4

see

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

Type declaration

  • init: CodeExpression

    Function used to initialize the state. The init function receives its arguments from the initArgs array expression. You can specify the function definition as either BSON type Code or String.

  • Optional initArgs?: ArrayExpression<any>

    Arguments passed to the init function.

  • accumulate: CodeExpression

    Function used to accumulate documents. The accumulate function receives its arguments from the current state and accumulateArgs array expression. The result of the accumulate function becomes the new state. You can specify the function definition as either BSON type Code or String.

  • accumulateArgs: ArrayExpression<any>

    Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function.

  • merge: CodeExpression

    Function used to merge two internal states. merge must be either a String or Code BSON type. merge returns the combined result of the two merged states. For information on when the merge function is called, see Merge Two States with $merge.

  • Optional finalize?: CodeExpression

    Function used to update the result of the accumulation.

  • lang: "js"

    The language used in the $accumulator code.

Generated using TypeDoc