Package com.mongodb.client.model
Class Aggregates
- java.lang.Object
-
- com.mongodb.client.model.Aggregates
-
public final class Aggregates extends Object
Builders for aggregation pipeline stages.- Since:
- 3.1
- MongoDB documentation
- Aggregation pipeline
- Since server release
- 2.2
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Bson
addFields(Field<?>... fields)
Creates an $addFields pipeline stagestatic Bson
addFields(List<Field<?>> fields)
Creates an $addFields pipeline stagestatic <TExpression,Boundary>
Bsonbucket(TExpression groupBy, List<Boundary> boundaries)
Creates a $bucket pipeline stagestatic <TExpression,TBoundary>
Bsonbucket(TExpression groupBy, List<TBoundary> boundaries, BucketOptions options)
Creates a $bucket pipeline stagestatic <TExpression>
BsonbucketAuto(TExpression groupBy, int buckets)
Creates a $bucketAuto pipeline stagestatic <TExpression>
BsonbucketAuto(TExpression groupBy, int buckets, BucketAutoOptions options)
Creates a $bucketAuto pipeline stagestatic Bson
count()
Creates a $count pipeline stage using the field name "count" to store the resultstatic Bson
count(String field)
Creates a $count pipeline stage using the named field to store the resultstatic Bson
facet(Facet... facets)
Creates a facet pipeline stagestatic Bson
facet(List<Facet> facets)
Creates a facet pipeline stagestatic <TExpression>
BsongraphLookup(String from, TExpression startWith, String connectFromField, String connectToField, String as)
Creates a graphLookup pipeline stage for the specified filterstatic <TExpression>
BsongraphLookup(String from, TExpression startWith, String connectFromField, String connectToField, String as, GraphLookupOptions options)
Creates a graphLookup pipeline stage for the specified filterstatic <TExpression>
Bsongroup(TExpression id, BsonField... fieldAccumulators)
Creates a $group pipeline stage for the specified filterstatic <TExpression>
Bsongroup(TExpression id, List<BsonField> fieldAccumulators)
Creates a $group pipeline stage for the specified filterstatic Bson
limit(int limit)
Creates a $limit pipeline stage for the specified filterstatic Bson
lookup(String from, String localField, String foreignField, String as)
Creates a $lookup pipeline stage, joining the current collection with the one specified in from using equality match between the local field and the foreign fieldstatic Bson
lookup(String from, List<? extends Bson> pipeline, String as)
Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipelinestatic <TExpression>
Bsonlookup(String from, List<Variable<TExpression>> let, List<? extends Bson> pipeline, String as)
Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipelinestatic Bson
match(Bson filter)
Creates a $match pipeline stage for the specified filterstatic Bson
merge(MongoNamespace namespace)
Creates a $merge pipeline stage that merges into the specified namespacestatic Bson
merge(MongoNamespace namespace, MergeOptions options)
Creates a $merge pipeline stage that merges into the specified namespace using the specified options.static Bson
merge(String collectionName)
Creates a $merge pipeline stage that merges into the specified collectionstatic Bson
merge(String collectionName, MergeOptions options)
Creates a $merge pipeline stage that merges into the specified collection using the specified options.static Bson
out(String collectionName)
Creates a $out pipeline stage that writes into the specified collectionstatic Bson
out(String databaseName, String collectionName)
Creates a $out pipeline stage that supports outputting to a different database.static Bson
out(Bson destination)
Creates a $out pipeline stage that writes out to the specified destinationstatic Bson
project(Bson projection)
Creates a $project pipeline stage for the specified projectionstatic <TExpression>
BsonreplaceRoot(TExpression value)
Creates a $replaceRoot pipeline stagestatic <TExpression>
BsonreplaceWith(TExpression value)
Creates a $replaceRoot pipeline stagestatic Bson
sample(int size)
Creates a $sample pipeline stage with the specified sample sizestatic Bson
skip(int skip)
Creates a $skip pipeline stagestatic Bson
sort(Bson sort)
Creates a $sort pipeline stage for the specified sort specificationstatic <TExpression>
BsonsortByCount(TExpression filter)
Creates a $sortByCount pipeline stage for the specified filterstatic Bson
unionWith(String collection, List<? extends Bson> pipeline)
Creates a $unionWith pipeline stage.static Bson
unwind(String fieldName)
Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a'$'
sign.static Bson
unwind(String fieldName, UnwindOptions unwindOptions)
Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a'$'
sign.
-
-
-
Method Detail
-
addFields
public static Bson addFields(Field<?>... fields)
Creates an $addFields pipeline stage- Parameters:
fields
- the fields to add- Returns:
- the $addFields pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $addFields
- Since server release
- 3.4
-
addFields
public static Bson addFields(List<Field<?>> fields)
Creates an $addFields pipeline stage- Parameters:
fields
- the fields to add- Returns:
- the $addFields pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $addFields
- Since server release
- 3.4
-
bucket
public static <TExpression,Boundary> Bson bucket(TExpression groupBy, List<Boundary> boundaries)
Creates a $bucket pipeline stage
-
bucket
public static <TExpression,TBoundary> Bson bucket(TExpression groupBy, List<TBoundary> boundaries, BucketOptions options)
Creates a $bucket pipeline stage- Type Parameters:
TExpression
- the groupBy expression typeTBoundary
- the boundary type- Parameters:
groupBy
- the criteria to group Byboundaries
- the boundaries of the bucketsoptions
- the optional values for the $bucket stage- Returns:
- the $bucket pipeline stage
- Since:
- 3.4
-
bucketAuto
public static <TExpression> Bson bucketAuto(TExpression groupBy, int buckets)
Creates a $bucketAuto pipeline stage- Type Parameters:
TExpression
- the groupBy expression type- Parameters:
groupBy
- the criteria to group Bybuckets
- the number of the buckets- Returns:
- the $bucketAuto pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $bucketAuto
- Since server release
- 3.4
-
bucketAuto
public static <TExpression> Bson bucketAuto(TExpression groupBy, int buckets, BucketAutoOptions options)
Creates a $bucketAuto pipeline stage- Type Parameters:
TExpression
- the groupBy expression type- Parameters:
groupBy
- the criteria to group Bybuckets
- the number of the bucketsoptions
- the optional values for the $bucketAuto stage- Returns:
- the $bucketAuto pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $bucketAuto
- Since server release
- 3.4
-
count
public static Bson count()
Creates a $count pipeline stage using the field name "count" to store the result
-
count
public static Bson count(String field)
Creates a $count pipeline stage using the named field to store the result
-
match
public static Bson match(Bson filter)
Creates a $match pipeline stage for the specified filter
-
project
public static Bson project(Bson projection)
Creates a $project pipeline stage for the specified projection- Parameters:
projection
- the projection- Returns:
- the $project pipeline stage
- See Also:
Projections
- MongoDB documentation
- $project
-
sort
public static Bson sort(Bson sort)
Creates a $sort pipeline stage for the specified sort specification
-
sortByCount
public static <TExpression> Bson sortByCount(TExpression filter)
Creates a $sortByCount pipeline stage for the specified filter- Type Parameters:
TExpression
- the expression type- Parameters:
filter
- the filter specification- Returns:
- the $sortByCount pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $sortByCount
- Since server release
- 3.4
-
skip
public static Bson skip(int skip)
Creates a $skip pipeline stage- Parameters:
skip
- the number of documents to skip- Returns:
- the $skip pipeline stage
- MongoDB documentation
- $skip
-
limit
public static Bson limit(int limit)
Creates a $limit pipeline stage for the specified filter- Parameters:
limit
- the limit- Returns:
- the $limit pipeline stage
- MongoDB documentation
- $limit
-
lookup
public static Bson lookup(String from, String localField, String foreignField, String as)
Creates a $lookup pipeline stage, joining the current collection with the one specified in from using equality match between the local field and the foreign field- Parameters:
from
- the name of the collection in the same database to perform the join with.localField
- the field from the local collection to match values against.foreignField
- the field in the from collection to match values against.as
- the name of the new array field to add to the input documents.- Returns:
- the $lookup pipeline stage
- Since:
- 3.2
-
lookup
public static Bson lookup(String from, List<? extends Bson> pipeline, String as)
Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipeline- Parameters:
from
- the name of the collection in the same database to perform the join with.pipeline
- the pipeline to run on the joined collection.as
- the name of the new array field to add to the input documents.- Returns:
- the $lookup pipeline stage
- Since:
- 3.7
-
lookup
public static <TExpression> Bson lookup(String from, @Nullable List<Variable<TExpression>> let, List<? extends Bson> pipeline, String as)
Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipeline- Type Parameters:
TExpression
- the Variable value expression type- Parameters:
from
- the name of the collection in the same database to perform the join with.let
- the variables to use in the pipeline field stages.pipeline
- the pipeline to run on the joined collection.as
- the name of the new array field to add to the input documents.- Returns:
- the $lookup pipeline stage
- Since:
- 3.7
-
graphLookup
public static <TExpression> Bson graphLookup(String from, TExpression startWith, String connectFromField, String connectToField, String as)
Creates a graphLookup pipeline stage for the specified filter- Type Parameters:
TExpression
- the expression type- Parameters:
from
- the collection to querystartWith
- the expression to start the graph lookup withconnectFromField
- the from fieldconnectToField
- the to fieldas
- name of field in output document- Returns:
- the $graphLookup pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $graphLookup
- Since server release
- 3.4
-
graphLookup
public static <TExpression> Bson graphLookup(String from, TExpression startWith, String connectFromField, String connectToField, String as, GraphLookupOptions options)
Creates a graphLookup pipeline stage for the specified filter- Type Parameters:
TExpression
- the expression type- Parameters:
from
- the collection to querystartWith
- the expression to start the graph lookup withconnectFromField
- the from fieldconnectToField
- the to fieldas
- name of field in output documentoptions
- optional values for the graphLookup- Returns:
- the $graphLookup pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $graphLookup
- Since server release
- 3.4
-
group
public static <TExpression> Bson group(@Nullable TExpression id, BsonField... fieldAccumulators)
Creates a $group pipeline stage for the specified filter- Type Parameters:
TExpression
- the expression type- Parameters:
id
- the id expression for the group, which may be nullfieldAccumulators
- zero or more field accumulator pairs- Returns:
- the $group pipeline stage
- MongoDB documentation
- $group
- Expressions
-
group
public static <TExpression> Bson group(@Nullable TExpression id, List<BsonField> fieldAccumulators)
Creates a $group pipeline stage for the specified filter- Type Parameters:
TExpression
- the expression type- Parameters:
id
- the id expression for the group, which may be nullfieldAccumulators
- zero or more field accumulator pairs- Returns:
- the $group pipeline stage
- MongoDB documentation
- $group
- Expressions
-
unionWith
public static Bson unionWith(String collection, List<? extends Bson> pipeline)
Creates a $unionWith pipeline stage.- Parameters:
collection
- the name of the collection in the same database to perform the union with.pipeline
- the pipeline to run on the union.- Returns:
- the $unionWith pipeline stage
- Since:
- 4.1
- MongoDB documentation
- $unionWith
- Since server release
- 4.4
-
unwind
public static Bson unwind(String fieldName)
Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a'$'
sign.- Parameters:
fieldName
- the field name, prefixed by a'$' sign
- Returns:
- the $unwind pipeline stage
- MongoDB documentation
- $unwind
-
unwind
public static Bson unwind(String fieldName, UnwindOptions unwindOptions)
Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a'$'
sign.
-
out
public static Bson out(String collectionName)
Creates a $out pipeline stage that writes into the specified collection- Parameters:
collectionName
- the collection name- Returns:
- the $out pipeline stage
- MongoDB documentation
- $out
-
out
public static Bson out(String databaseName, String collectionName)
Creates a $out pipeline stage that supports outputting to a different database.
-
out
public static Bson out(Bson destination)
Creates a $out pipeline stage that writes out to the specified destination- Parameters:
destination
- the destination details- Returns:
- the $out pipeline stage
- Since:
- 4.1
- MongoDB documentation
- $out
-
merge
public static Bson merge(String collectionName)
Creates a $merge pipeline stage that merges into the specified collection
-
merge
public static Bson merge(MongoNamespace namespace)
Creates a $merge pipeline stage that merges into the specified namespace
-
merge
public static Bson merge(String collectionName, MergeOptions options)
Creates a $merge pipeline stage that merges into the specified collection using the specified options.
-
merge
public static Bson merge(MongoNamespace namespace, MergeOptions options)
Creates a $merge pipeline stage that merges into the specified namespace using the specified options.
-
replaceRoot
public static <TExpression> Bson replaceRoot(TExpression value)
Creates a $replaceRoot pipeline stage- Type Parameters:
TExpression
- the new root type- Parameters:
value
- the new root value- Returns:
- the $replaceRoot pipeline stage
- Since:
- 3.4
- MongoDB documentation
- $replaceRoot
- Since server release
- 3.4
-
replaceWith
public static <TExpression> Bson replaceWith(TExpression value)
Creates a $replaceRoot pipeline stageWith $replaceWith, you can promote an embedded document to the top-level. You can also specify a new document as the replacement.
The $replaceWith is an alias for
replaceRoot(Object)
.- Type Parameters:
TExpression
- the new root type- Parameters:
value
- the new root value- Returns:
- the $replaceRoot pipeline stage
- Since:
- 3.11
- MongoDB documentation
- $replaceWith
- Since server release
- 4.2
-
-