Skip to main content

MongoAccumulators

Definition of the accumulators in Bson that are used in MongoDB aggregation operations.


avg


avg(fieldName: string, expression: string) : com.mongodb.client.model.BsonField

Description

Creates an accumulator that calculates the average of the values of a field.

How To Use
_mongo.accumulators().avg('averagePrice', '$price');
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
expressionstringThe input field expression.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


bottom


bottom(fieldName: string, sortBy: org.bson.conversions.Bson, outExpression: string) : com.mongodb.client.model.BsonField

Description

Returns the bottom document based on the specified sort.

How To Use
_mongo.accumulators().bottom('loser', _mongo.sorts().ascending('score'), '$playerId');
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
sortByorg.bson.conversions.BsonThe sort to apply.
outExpressionstringThe output field expression.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


bottomN


bottomN(fieldName: string, sortBy: org.bson.conversions.Bson, outExpression: string, nExpression: long) : com.mongodb.client.model.BsonField

Description

Returns the bottom N documents based on the specified sort.

How To Use
_mongo.accumulators().bottomN('bottomThree', _mongo.sorts().ascending('score'), '$playerId', 3);
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
sortByorg.bson.conversions.BsonThe sort to apply.
outExpressionstringThe output field expression.
nExpressionlongThe number of values to return.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


first


first(fieldName: string, expression: string) : com.mongodb.client.model.BsonField

Description

Gets the field value from the first document in the ordered list.

How To Use
_mongo.accumulators().first('latestTotal', '$totalAmount');
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
expressionstringThe input field expression.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


firstN


firstN(fieldName: string, inExpression: string, nExpression: long) : com.mongodb.client.model.BsonField

Description

Gets the first N values of the field from the first documents in the ordered list.

How To Use
_mongo.accumulators().firstN('topThreeOrders', '$totalAmount', 3);
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
inExpressionstringThe input field expression.
nExpressionlongThe number of values to return.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


last


last(fieldName: string, expression: string) : com.mongodb.client.model.BsonField

Description

Gets the field value from the last document in the ordered list.

How To Use
_mongo.accumulators().last('lastTotal', '$totalAmount');
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
expressionstringThe input field expression.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


lastN


lastN(fieldName: string, inExpression: string, nExpression: long) : com.mongodb.client.model.BsonField

Description

Gets the last N values of the field from the last documents in the ordered list.

How To Use
_mongo.accumulators().lastN('lastThreeOrders', '$totalAmount', 3);
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
inExpressionstringThe input field expression.
nExpressionlongThe number of values to return.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


max


max(fieldName: string, expression: string) : com.mongodb.client.model.BsonField

Description

Creates an accumulator that returns the maximum value of the field.

How To Use
_mongo.accumulators().max('maxPrice', '$price');
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
expressionstringThe input field expression.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


maxN


maxN(fieldName: string, inExpression: string, nExpression: long) : com.mongodb.client.model.BsonField

Description

Returns the top N values of the field.

How To Use
_mongo.accumulators().maxN('topThreePrices', '$price', 3);
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
inExpressionstringThe input field expression.
nExpressionlongThe number of values to return.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


min


min(fieldName: string, expression: string) : com.mongodb.client.model.BsonField

Description

Creates an accumulator that returns the minimum value of the field.

How To Use
_mongo.accumulators().min('minPrice', '$price');
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
expressionstringThe input field expression.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


minN


minN(fieldName: string, inExpression: string, nExpression: long) : com.mongodb.client.model.BsonField

Description

Returns the bottom N values of the field.

How To Use
_mongo.accumulators().minN('bottomThreePrices', '$price', 3);
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
inExpressionstringThe input field expression.
nExpressionlongThe number of values to return.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


sum


sum(fieldName: string, expression: string) : com.mongodb.client.model.BsonField

Description

Creates an accumulator that calculates the sum of the values of a field.

How To Use
_mongo.accumulators().sum('totalPrice', '$price');
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
expressionstringThe input field expression.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


top


top(fieldName: string, sortBy: org.bson.conversions.Bson, outExpression: string) : com.mongodb.client.model.BsonField

Description

Returns the top document based on the specified sort.

How To Use
_mongo.accumulators().top('winner', _mongo.sorts().descending('score'), '$playerId');
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
sortByorg.bson.conversions.BsonThe sort to apply.
outExpressionstringThe output field expression.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.


topN


topN(fieldName: string, sortBy: org.bson.conversions.Bson, outExpression: string, nExpression: long) : com.mongodb.client.model.BsonField

Description

Returns the top N documents based on the specified sort.

How To Use
_mongo.accumulators().topN('topThree', _mongo.sorts().descending('score'), '$playerId', 3);
Attributes
NAMETYPEDESCRIPTION
fieldNamestringThe output field name.
sortByorg.bson.conversions.BsonThe sort to apply.
outExpressionstringThe output field expression.
nExpressionlongThe number of values to return.
Return

( com.mongodb.client.model.BsonField )

The BsonField accumulator.