Skip to main content

MongoAggregates

Definition of the aggregation pipeline stages in Bson used in MongoDB aggregation operations.


count​


count() : org.bson.conversions.Bson​

Description​

Counts the number of input documents.

How To Use​
_mongo.aggregates().count();
Return​

( org.bson.conversions.Bson )

The Bson aggregation stage.


group​


group(id: string, fieldAccumulators: com.mongodb.client.model.BsonField[]) : org.bson.conversions.Bson​

Description​

Groups the input documents by the specified field and applies the accumulators to the resulting groups.

How To Use​
_mongo.aggregates().group('$customerId', _mongo.accumulators().sum('total', '$price'));
Attributes​
NAMETYPEDESCRIPTION
idstringThe group field expression.
fieldAccumulatorscom.mongodb.client.model.BsonField[]The accumulators to apply to the groups.
Return​

( org.bson.conversions.Bson )

The Bson aggregation stage.


group(id: string, fieldAccumulators: java.util.List<com.mongodb.client.model.BsonField>) : org.bson.conversions.Bson​

Description​

Groups the input documents by the specified field and applies the accumulators to the resulting groups.

Attributes​
NAMETYPEDESCRIPTION
idstringThe group field expression.
fieldAccumulatorsjava.util.ListThe accumulators to apply to the groups.
Return​

( org.bson.conversions.Bson )

The Bson aggregation stage.


limit​


limit(limit: int) : org.bson.conversions.Bson​

Description​

Limits the input documents to the first N documents.

How To Use​
_mongo.aggregates().limit(5);
Attributes​
NAMETYPEDESCRIPTION
limitintThe maximum number of documents.
Return​

( org.bson.conversions.Bson )

The Bson aggregation stage.


lookup​


lookup(from: string, localField: string, foreignField: string, as: string) : org.bson.conversions.Bson​

Description​

Performs a join with another collection.

How To Use​
_mongo.aggregates().lookup('orders', 'customerId', '_id', 'orders');
Attributes​
NAMETYPEDESCRIPTION
fromstringThe collection to join.
localFieldstringThe field from the input documents.
foreignFieldstringThe field from the documents of the "from" collection.
asstringThe output field name.
Return​

( org.bson.conversions.Bson )

The Bson aggregation stage.


lookup(from: string, pipeline: java.util.List<?>, as: string) : org.bson.conversions.Bson​

Description​

Performs a join with another collection using a pipeline.

Attributes​
NAMETYPEDESCRIPTION
fromstringThe collection to join.
pipelinejava.util.ListThe aggregation pipeline to run on the from collection.
asstringThe output field name.
Return​

( org.bson.conversions.Bson )

The Bson aggregation stage.


match​


match(filter: org.bson.conversions.Bson) : org.bson.conversions.Bson​

Description​

Filters the input documents to select only those that match the specified filter.

How To Use​
_mongo.aggregates().match(_mongo.filters().eq('status', 'Active'));
Attributes​
NAMETYPEDESCRIPTION
filterorg.bson.conversions.BsonThe query filter.
Return​

( org.bson.conversions.Bson )

The Bson aggregation stage.


project​


project(projection: org.bson.conversions.Bson) : org.bson.conversions.Bson​

Description​

Transforms each input document, adding, removing or altering fields.

How To Use​
_mongo.aggregates().project(_mongo.projections().include('name', 'quantity'));
Attributes​
NAMETYPEDESCRIPTION
projectionorg.bson.conversions.BsonThe projection specification.
Return​

( org.bson.conversions.Bson )

The Bson aggregation stage.


skip​


skip(skip: int) : org.bson.conversions.Bson​

Description​

Skips the first N documents of the input.

How To Use​
_mongo.aggregates().skip(10);
Attributes​
NAMETYPEDESCRIPTION
skipintThe number of documents to skip.
Return​

( org.bson.conversions.Bson )

The Bson aggregation stage.


sort​


sort(sort: org.bson.conversions.Bson) : org.bson.conversions.Bson​

Description​

Sorts the input documents.

How To Use​
_mongo.aggregates().sort(_mongo.sorts().descending('date'));
Attributes​
NAMETYPEDESCRIPTION
sortorg.bson.conversions.BsonThe sort specification.
Return​

( org.bson.conversions.Bson )

The Bson aggregation stage.