Class BucketOperation
java.lang.Object
org.springframework.data.mongodb.core.aggregation.BucketOperationSupport<BucketOperation,BucketOperation.BucketOperationOutputBuilder>
org.springframework.data.mongodb.core.aggregation.BucketOperation
- All Implemented Interfaces:
AggregationOperation
,FieldsExposingAggregationOperation
public class BucketOperation
extends BucketOperationSupport<BucketOperation,BucketOperation.BucketOperationOutputBuilder>
implements FieldsExposingAggregationOperation
Encapsulates the aggregation framework
Bucket stage is typically used with
We recommend to use the static factory method
$bucket
-operation. Bucket stage is typically used with
Aggregation
and $facet
. Categorizes incoming documents into
groups, called buckets, based on a specified expression and bucket boundaries. We recommend to use the static factory method
Aggregation.bucket(String)
instead of creating instances of
this class directly.- Since:
- 1.10
- Author:
- Mark Paluch
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
BucketOperationSupport.OutputBuilder
implementation forBucketOperation
.static class
BucketOperationSupport.ExpressionBucketOperationBuilderSupport
implementation forBucketOperation
using SpEL expression basedBucketOperationSupport.Output
.Nested classes/interfaces inherited from class org.springframework.data.mongodb.core.aggregation.BucketOperationSupport
BucketOperationSupport.ExpressionBucketOperationBuilderSupport<B extends BucketOperationSupport.OutputBuilder<B,
T>, T extends BucketOperationSupport<T, B>>, BucketOperationSupport.OperationOutput, BucketOperationSupport.Output, BucketOperationSupport.OutputBuilder<B extends BucketOperationSupport.OutputBuilder<B, T>, T extends BucketOperationSupport<T, B>>, BucketOperationSupport.Outputs Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation
FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation
-
Constructor Summary
ConstructorDescriptionBucketOperation
(AggregationExpression groupByExpression) Creates a newBucketOperation
given agroup-by expression
.BucketOperation
(Field groupByField) Creates a newBucketOperation
given agroup-by field
. -
Method Summary
Modifier and TypeMethodDescriptionCreates a newBucketOperationSupport
given fieldName to add an output field to the resulting bucket documents.andOutput
(AggregationExpression expression) Creates a newBucketOperationSupport
given anAggregationExpression
to add an output field to the resulting bucket documents.andOutputExpression
(String expression, Object... params) Creates a newBucketOperationSupport.ExpressionBucketOperationBuilderSupport
given a SpEL expression and optional params to add an output field to the resulting bucket documents.Return the MongoDB operator that is used for thisAggregationOperation
.protected BucketOperation
Implementation hook to create a new bucket operation.org.bson.Document
toDocument
(AggregationOperationContext context) withBoundaries
(Object... boundaries) Configures boundaries and return a newBucketOperation
.withDefaultBucket
(Object literal) Configures a default bucket literal and return a newBucketOperation
.Methods inherited from class org.springframework.data.mongodb.core.aggregation.BucketOperationSupport
andOutput, andOutputCount, getFields
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.data.mongodb.core.aggregation.AggregationOperation
toPipelineStages
Methods inherited from interface org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation
getFields, inheritsFields
-
Constructor Details
-
BucketOperation
Creates a newBucketOperation
given agroup-by field
.- Parameters:
groupByField
- must not be null.
-
BucketOperation
Creates a newBucketOperation
given agroup-by expression
.- Parameters:
groupByExpression
- must not be null.
-
-
Method Details
-
toDocument
Description copied from interface:AggregationOperation
- Specified by:
toDocument
in interfaceAggregationOperation
- Overrides:
toDocument
in classBucketOperationSupport<BucketOperation,
BucketOperation.BucketOperationOutputBuilder> - Parameters:
context
- theAggregationOperationContext
to operate within. Must not be null.- Returns:
- the Document
-
getOperator
Description copied from interface:AggregationOperation
Return the MongoDB operator that is used for thisAggregationOperation
. Aggregation operations should implement this method to avoid document rendering.- Specified by:
getOperator
in interfaceAggregationOperation
- Returns:
- the operator used for this
AggregationOperation
.
-
withDefaultBucket
Configures a default bucket literal and return a newBucketOperation
.- Parameters:
literal
- must not be null.- Returns:
- new instance of
BucketOperation
.
-
withBoundaries
Configures boundaries and return a newBucketOperation
. Existing boundaries are preserved and the new boundaries are appended.- Parameters:
boundaries
- must not be null.- Returns:
- new instance of
BucketOperation
.
-
newBucketOperation
Description copied from class:BucketOperationSupport
Implementation hook to create a new bucket operation.- Specified by:
newBucketOperation
in classBucketOperationSupport<BucketOperation,
BucketOperation.BucketOperationOutputBuilder> - Parameters:
outputs
- the outputs- Returns:
- the new bucket operation.
-
andOutputExpression
public BucketOperation.ExpressionBucketOperationBuilder andOutputExpression(String expression, Object... params) Description copied from class:BucketOperationSupport
Creates a newBucketOperationSupport.ExpressionBucketOperationBuilderSupport
given a SpEL expression and optional params to add an output field to the resulting bucket documents.- Specified by:
andOutputExpression
in classBucketOperationSupport<BucketOperation,
BucketOperation.BucketOperationOutputBuilder> - Parameters:
expression
- the SpEL expression, must not be null or empty.params
- must not be null- Returns:
- new instance of
BucketOperationSupport.ExpressionBucketOperationBuilderSupport
to createBucketOperation
.
-
andOutput
Description copied from class:BucketOperationSupport
Creates a newBucketOperationSupport
given anAggregationExpression
to add an output field to the resulting bucket documents.- Specified by:
andOutput
in classBucketOperationSupport<BucketOperation,
BucketOperation.BucketOperationOutputBuilder> - Parameters:
expression
- the SpEL expression, must not be null or empty.- Returns:
- never null.
-
andOutput
Description copied from class:BucketOperationSupport
Creates a newBucketOperationSupport
given fieldName to add an output field to the resulting bucket documents.BucketOperationSupport
exposes accumulation operations that can be applied to fieldName.- Specified by:
andOutput
in classBucketOperationSupport<BucketOperation,
BucketOperation.BucketOperationOutputBuilder> - Parameters:
fieldName
- must not be null or empty.- Returns:
- never null.
-