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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| id | string | The group field expression. |
| fieldAccumulators | com.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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| id | string | The group field expression. |
| fieldAccumulators | java.util.List | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| limit | int | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| from | string | The collection to join. |
| localField | string | The field from the input documents. |
| foreignField | string | The field from the documents of the "from" collection. |
| as | string | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| from | string | The collection to join. |
| pipeline | java.util.List | The aggregation pipeline to run on the from collection. |
| as | string | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| filter | org.bson.conversions.Bson | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| projection | org.bson.conversions.Bson | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| skip | int | The 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| sort | org.bson.conversions.Bson | The sort specification. |
Return
( org.bson.conversions.Bson )
The Bson aggregation stage.