accumulator

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package accumulator Custom Aggregation Expression Operators

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToSet

func AddToSet[T expression.AnyExpression](e T) accumulatorOperator

AddToSet Changed in version 5.0. $addToSet $addToSet returns an array of all unique values that results from applying an expression to each document in a group. The order of the elements in the returned array is unspecified. $addToSet is available in these stages: $bucket $bucketAuto $group $setWindowFields (Available starting in MongoDB 5.0)

func Avg

func Avg[T expression.AnyExpression](e []T) accumulatorOperator

Avg Returns the average value of the numeric values. $avg ignores non-numeric values. $avg is available in these stages: $addFields (Available starting in MongoDB 3.4) $bucket $bucketAuto $group $match stage that includes an $expr expression $project $replaceRoot (Available starting in MongoDB 3.4) $replaceWith (Available starting in MongoDB 4.2) $set (Available starting in MongoDB 4.2) $setWindowFields (Available starting in MongoDB 5.0) In MongoDB 3.2 and earlier, $avg is available in the $group stage only.

func Bottom

func Bottom[T expression.AnyExpression](sortBy bsonx.Bson, out T) accumulatorOperator

Bottom New in version 5.2. Returns the bottom element within a group according to the specified sort order.

{
  $bottom:
     {
        sortBy: { <field1>: <sort order>, <field2>: <sort order> ... },
        output: <expression>
     }
}

func BottomN

func BottomN[T expression.AnyExpression, N expression.IntExpression](sortBy bsonx.Bson, out T, n N) accumulatorOperator

BottomN New in version 5.2. Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group.

func Count

func Count() accumulatorOperator

Count New in version 5.0. $count Returns the number of documents in a group. $count is available in these stages: $bucket $bucketAuto $group $setWindowFields (Available starting in MongoDB 5.0)

func First

func First[T expression.AnyExpression](e T) accumulatorOperator

First Changed in version 5.0. Returns the value that results from applying an expression to the first document in a group of documents. Only meaningful when documents are in a defined order. $first is available in these stages: $bucket $bucketAuto $group $setWindowFields (Available starting in MongoDB 5.0)

func FirstN

func FirstN[T expression.AnyExpression, N expression.IntExpression](in T, n N) accumulatorOperator

FirstN New in version 5.2. Returns an aggregation of the first n elements within a group. The elements returned are meaningful only if in a specified sort order. If the group contains fewer than n elements, $firstN returns all elements in the group.

func Last

func Last[T expression.AnyExpression](e T) accumulatorOperator

Last Changed in version 5.0. Returns the value that results from applying an expression to the last document in a group of documents. Only meaningful when documents are in a defined order. $last is available in these stages: $bucket $bucketAuto $group $setWindowFields (Available starting in MongoDB 5.0)

func LastN

func LastN[T expression.AnyExpression, N expression.IntExpression](in T, n N) accumulatorOperator

LastN New in version 5.2. Returns an aggregation of the last n elements within a group. The elements returned are meaningful only if in a specified sort order. If the group contains fewer than n elements, $lastN returns all elements in the group.

func Max

func Max[T expression.AnyExpression](e T) accumulatorOperator

Max Returns the maximum value. $max compares both value and type, using the specified BSON comparison order for values of different types. $max is available in these stages: $addFields (Available starting in MongoDB 3.4) $bucket $bucketAuto $group $match stage that includes an $expr expression $project $replaceRoot (Available starting in MongoDB 3.4) $replaceWith (Available starting in MongoDB 4.2) $set (Available starting in MongoDB 4.2) $setWindowFields (Available starting in MongoDB 5.0) In MongoDB 3.2 and earlier, $max is available in the $group stage only.

func MaxN

func MaxN[T expression.AnyExpression, N expression.IntExpression](in T, n N) accumulatorOperator

MaxN New in version 5.2. Returns an aggregation of the maxmimum value n elements within a group. If the group contains fewer than n elements, $maxN returns all elements in the group.

func Min

func Min[T expression.AnyExpression](e T) accumulatorOperator

Min Returns the minimum value. $min compares both value and type, using the specified BSON comparison order for values of different types. $min is available in these stages: $addFields (Available starting in MongoDB 3.4) $bucket $bucketAuto $group $match stage that includes an $expr expression $project $replaceRoot (Available starting in MongoDB 3.4) $replaceWith (Available starting in MongoDB 4.2) $set (Available starting in MongoDB 4.2) $setWindowFields (Available starting in MongoDB 5.0) In MongoDB 3.2 and earlier, $min is available in the $group stage only.

func Push

func Push[T expression.AnyExpression](e T) accumulatorOperator

Push returns an array of all values that result from applying an expression to documents. $push is available in these stages: $bucket $bucketAuto $group $setWindowFields (Available starting in MongoDB 5.0)

func StdDevPop

func StdDevPop[T expression.AnyExpression](e []T) accumulatorOperator

StdDevPop Changed in version 5.0. Calculates the population standard deviation of the input values. Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population. $stdDevPop ignores non-numeric values. If the values represent only a sample of a population of data from which to generalize about the population, use $stdDevSamp instead. $stdDevPop is available in these stages: $addFields (Available starting in MongoDB 3.4) $group $match stage that includes an $expr expression $project $replaceRoot (Available starting in MongoDB 3.4) $replaceWith (Available starting in MongoDB 4.2) $set (Available starting in MongoDB 4.2) $setWindowFields (Available starting in MongoDB 5.0)

func StdDevSamp

func StdDevSamp[T expression.AnyExpression](e []T) accumulatorOperator

StdDevSamp Changed in version 5.0. Calculates the sample standard deviation of the input values. Use if the values encompass a sample of a population of data from which to generalize about the population. $stdDevSamp ignores non-numeric values. If the values represent the entire population of data or you do not wish to generalize about a larger population, use $stdDevPop instead. $stdDevSamp is available in these stages: $addFields (Available starting in MongoDB 3.4) $group $match stage that includes an $expr expression $project $replaceRoot (Available starting in MongoDB 3.4) $replaceWith (Available starting in MongoDB 4.2) $set (Available starting in MongoDB 4.2) $setWindowFields (Available starting in MongoDB 5.0)

func Sum

func Sum[T expression.AnyExpression](e []T) accumulatorOperator

Sum Changed in version 5.0. Calculates and returns the collective sum of numeric values. $sum ignores non-numeric values. $sum is available in these stages: $addFields (Available starting in MongoDB 3.4) $bucket $bucketAuto $group $match stage that includes an $expr expression $project $replaceRoot (Available starting in MongoDB 3.4) $replaceWith (Available starting in MongoDB 4.2) $set (Available starting in MongoDB 4.2) $setWindowFields (Available starting in MongoDB 5.0) In MongoDB 3.2 and earlier, $sum is available in the $group stage only.

func Top

func Top[T expression.AnyExpression](sortBy bsonx.Bson, out T) accumulatorOperator

Top New in version 5.2. Returns the top element within a group according to the specified sort order.

func TopN

func TopN[T expression.AnyExpression, N expression.IntExpression](sortBy bsonx.Bson, out T, n N) accumulatorOperator

TopN New in version 5.2. Returns an aggregation of the top n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $topN returns all elements in the group.

Types

type AccumulatorBson

type AccumulatorBson bsonx.Bson

func New

func New[T AccumulatorExpression](fieldName string, e T) AccumulatorBson

type AccumulatorExpression

type AccumulatorExpression interface {
	expression.Expression
	accumulatorOperator | CustomOperator
}

type CustomOperator

type CustomOperator struct {
	// contains filtered or unexported fields
}

func Accumulator

func Accumulator(
	initFunction string,
	initArgs []string, accumulateFunction string,
	accumulateArgs []string, mergeFunction string,
	finalizeFunction string, lang string,
) CustomOperator

Accumulator New in version 4.4. 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. $accumulator is available in these stages: $bucket $bucketAuto $group The $accumulator operator has this syntax:

{
 $accumulator: {
   init: <code>,
   initArgs: <array expression>,        // Optional
   accumulate: <code>,
   accumulateArgs: <array expression>,
   merge: <code>,
   finalize: <code>,                    // Optional
   lang: <string>
 }
}

func Function

func Function(body string, initArgs []string, lang string) CustomOperator

Function New in version 4.4. Defines a custom aggregation function or expression in JavaScript. You can use the $function operator to define custom functions to implement behavior not supported by the MongoDB Query Language. See also $accumulator. The $function operator has the following syntax:

{
 $function: {
   body: <code>, args: <array expression>, lang: "js"
 }
}

func (CustomOperator) Exp

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL