Package com.mongodb.client.model
Class Accumulators
java.lang.Object
com.mongodb.client.model.Accumulators
Builders for accumulators used in the group pipeline stage of an aggregation pipeline.
- Since:
- 3.1
- MongoDB documentation
- Aggregation pipeline
- Accumulators
- Expressions
- Since server release
- 2.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic BsonField
accumulator
(String fieldName, String initFunction, String accumulateFunction, String mergeFunction) Creates an $accumulator pipeline stagestatic BsonField
accumulator
(String fieldName, String initFunction, String accumulateFunction, String mergeFunction, String finalizeFunction) Creates an $accumulator pipeline stagestatic BsonField
accumulator
(String fieldName, String initFunction, String accumulateFunction, String mergeFunction, String finalizeFunction, String lang) Creates an $accumulator pipeline stagestatic BsonField
accumulator
(String fieldName, String initFunction, List<String> initArgs, String accumulateFunction, List<String> accumulateArgs, String mergeFunction, String finalizeFunction) Creates an $accumulator pipeline stagestatic BsonField
accumulator
(String fieldName, String initFunction, List<String> initArgs, String accumulateFunction, List<String> accumulateArgs, String mergeFunction, String finalizeFunction, String lang) Creates an $accumulator pipeline stagestatic <TExpression>
BsonFieldGets a field name for a $group operation representing all unique values that results from applying the given expression to each document in a group of documents that share the same group by key.static <TExpression>
BsonFieldGets a field name for a $group operation representing the average of the values of the given expression when applied to all members of the group.static <TExpression>
BsonFieldGets a field name for a $group operation representing the value of the given expression when applied to the first member of the group.static <TExpression>
BsonFieldGets a field name for a $group operation representing the value of the given expression when applied to the last member of the group.static <TExpression>
BsonFieldGets a field name for a $group operation representing the maximum of the values of the given expression when applied to all members of the group.static <TExpression>
BsonFieldmergeObjects
(String fieldName, TExpression expression) Gets a field name for a $group operation representing the result of merging the fields of the documents.static <TExpression>
BsonFieldGets a field name for a $group operation representing the minimum of the values of the given expression when applied to all members of the group.static <TExpression>
BsonFieldGets a field name for a $group operation representing an array of all values that results from applying an expression to each document in a group of documents that share the same group by key.static <TExpression>
BsonFieldGets a field name for a $group operation representing the sample standard deviation of the values of the given expression when applied to all members of the group.static <TExpression>
BsonFieldstdDevSamp
(String fieldName, TExpression expression) Gets a field name for a $group operation representing the sample standard deviation of the values of the given expression when applied to all members of the group.static <TExpression>
BsonFieldGets a field name for a $group operation representing the sum of the values of the given expression when applied to all members of the group.
-
Method Details
-
sum
Gets a field name for a $group operation representing the sum of the values of the given expression when applied to all members of the group.- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- MongoDB documentation
- $sum
-
avg
Gets a field name for a $group operation representing the average of the values of the given expression when applied to all members of the group.- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- MongoDB documentation
- $avg
-
first
Gets a field name for a $group operation representing the value of the given expression when applied to the first member of the group.- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- MongoDB documentation
- $first
-
last
Gets a field name for a $group operation representing the value of the given expression when applied to the last member of the group.- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- MongoDB documentation
- $last
-
max
Gets a field name for a $group operation representing the maximum of the values of the given expression when applied to all members of the group.- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- MongoDB documentation
- $max
-
min
Gets a field name for a $group operation representing the minimum of the values of the given expression when applied to all members of the group.- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- MongoDB documentation
- $min
-
push
Gets a field name for a $group operation representing an array of all values that results from applying an expression to each document in a group of documents that share the same group by key.- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- MongoDB documentation
- $push
-
addToSet
Gets a field name for a $group operation representing all unique values that results from applying the given expression to each document in a group of documents that share the same group by key.- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- MongoDB documentation
- $addToSet
-
mergeObjects
Gets a field name for a $group operation representing the result of merging the fields of the documents. If documents to merge include the same field name, the field, in the resulting document, has the value from the last document merged for the field.- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- Since:
- 4.4
- MongoDB documentation
- $mergeObjects
-
stdDevPop
Gets a field name for a $group operation representing the sample standard deviation of the values of the given expression when applied to all members of the group.Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population.
- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- Since:
- 3.2
- MongoDB documentation
- $stdDevPop
- Since server release
- 3.2
-
stdDevSamp
Gets a field name for a $group operation representing the sample standard deviation of the values of the given expression when applied to all members of the group.Use if the values encompass a sample of a population of data from which to generalize about the population.
- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the field
- Since:
- 3.2
- MongoDB documentation
- $stdDevSamp
- Since server release
- 3.2
-
accumulator
public static BsonField accumulator(String fieldName, String initFunction, String accumulateFunction, String mergeFunction) Creates an $accumulator pipeline stage- Parameters:
fieldName
- the field nameinitFunction
- a function used to initialize the stateaccumulateFunction
- a function used to accumulate documentsmergeFunction
- a function used to merge two internal states, e.g. accumulated on different shards or threads. It returns the resulting state of the accumulator.- Returns:
- the $accumulator pipeline stage
- Since:
- 4.1
- MongoDB documentation
- $accumulator
- Since server release
- 4.4
-
accumulator
public static BsonField accumulator(String fieldName, String initFunction, String accumulateFunction, String mergeFunction, @Nullable String finalizeFunction) Creates an $accumulator pipeline stage- Parameters:
fieldName
- the field nameinitFunction
- a function used to initialize the stateaccumulateFunction
- a function used to accumulate documentsmergeFunction
- a function used to merge two internal states, e.g. accumulated on different shards or threads. It returns the resulting state of the accumulator.finalizeFunction
- a function used to finalize the state and return the result (may be null)- Returns:
- the $accumulator pipeline stage
- Since:
- 4.1
- MongoDB documentation
- $accumulator
- Since server release
- 4.4
-
accumulator
public static BsonField accumulator(String fieldName, String initFunction, @Nullable List<String> initArgs, String accumulateFunction, @Nullable List<String> accumulateArgs, String mergeFunction, @Nullable String finalizeFunction) Creates an $accumulator pipeline stage- Parameters:
fieldName
- the field nameinitFunction
- a function used to initialize the stateinitArgs
- init function’s arguments (may be null)accumulateFunction
- a function used to accumulate documentsaccumulateArgs
- additional accumulate function’s arguments (may be null). The first argument to the function is ‘state’.mergeFunction
- a function used to merge two internal states, e.g. accumulated on different shards or threads. It returns the resulting state of the accumulator.finalizeFunction
- a function used to finalize the state and return the result (may be null)- Returns:
- the $accumulator pipeline stage
- Since:
- 4.1
- MongoDB documentation
- $accumulator
- Since server release
- 4.4
-
accumulator
public static BsonField accumulator(String fieldName, String initFunction, String accumulateFunction, String mergeFunction, @Nullable String finalizeFunction, String lang) Creates an $accumulator pipeline stage- Parameters:
fieldName
- the field nameinitFunction
- a function used to initialize the stateaccumulateFunction
- a function used to accumulate documentsmergeFunction
- a function used to merge two internal states, e.g. accumulated on different shards or threads. It returns the resulting state of the accumulator.finalizeFunction
- a function used to finalize the state and return the result (may be null)lang
- a language specifier- Returns:
- the $accumulator pipeline stage
- Since:
- 4.1
- MongoDB documentation
- $accumulator
- Since server release
- 4.4
-
accumulator
public static BsonField accumulator(String fieldName, String initFunction, @Nullable List<String> initArgs, String accumulateFunction, @Nullable List<String> accumulateArgs, String mergeFunction, @Nullable String finalizeFunction, String lang) Creates an $accumulator pipeline stage- Parameters:
fieldName
- the field nameinitFunction
- a function used to initialize the stateinitArgs
- init function’s arguments (may be null)accumulateFunction
- a function used to accumulate documentsaccumulateArgs
- additional accumulate function’s arguments (may be null). The first argument to the function is ‘state’.mergeFunction
- a function used to merge two internal states, e.g. accumulated on different shards or threads. It returns the resulting state of the accumulator.finalizeFunction
- a function used to finalize the state and return the result (may be null)lang
- a language specifier- Returns:
- the $accumulator pipeline stage
- Since:
- 4.1
- MongoDB documentation
- $accumulator
- Since server release
- 4.4
-