Module spring.data.mongodb
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
Nested ClassesModifier and TypeClassDescriptionstatic classBucketOperationSupport.OutputBuilderimplementation forBucketOperation.static classBucketOperationSupport.ExpressionBucketOperationBuilderSupportimplementation forBucketOperationusing 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
ConstructorsConstructorDescriptionBucketOperation(AggregationExpression groupByExpression) Creates a newBucketOperationgiven agroup-by expression.BucketOperation(Field groupByField) Creates a newBucketOperationgiven agroup-by field. -
Method Summary
Modifier and TypeMethodDescriptionCreates a newBucketOperationSupportgiven fieldName to add an output field to the resulting bucket documents.andOutput(AggregationExpression expression) Creates a newBucketOperationSupportgiven anAggregationExpressionto add an output field to the resulting bucket documents.andOutputExpression(String expression, Object... params) Creates a newBucketOperationSupport.ExpressionBucketOperationBuilderSupportgiven 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 BucketOperationImplementation hook to create a new bucket operation.org.bson.DocumenttoDocument(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, getFieldsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.mongodb.core.aggregation.AggregationOperation
toPipelineStagesMethods inherited from interface org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation
getFields, inheritsFields
-
Constructor Details
-
BucketOperation
Creates a newBucketOperationgiven agroup-by field.- Parameters:
groupByField- must not be null.
-
BucketOperation
Creates a newBucketOperationgiven agroup-by expression.- Parameters:
groupByExpression- must not be null.
-
-
Method Details
-
toDocument
Description copied from interface:AggregationOperation- Specified by:
toDocumentin interfaceAggregationOperation- Overrides:
toDocumentin classBucketOperationSupport<BucketOperation,BucketOperation.BucketOperationOutputBuilder> - Parameters:
context- theAggregationOperationContextto operate within. Must not be null.- Returns:
- the Document
-
getOperator
Description copied from interface:AggregationOperationReturn the MongoDB operator that is used for thisAggregationOperation. Aggregation operations should implement this method to avoid document rendering.- Specified by:
getOperatorin 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:BucketOperationSupportImplementation hook to create a new bucket operation.- Specified by:
newBucketOperationin 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:BucketOperationSupportCreates a newBucketOperationSupport.ExpressionBucketOperationBuilderSupportgiven a SpEL expression and optional params to add an output field to the resulting bucket documents.- Specified by:
andOutputExpressionin 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.ExpressionBucketOperationBuilderSupportto createBucketOperation.
-
andOutput
Description copied from class:BucketOperationSupportCreates a newBucketOperationSupportgiven anAggregationExpressionto add an output field to the resulting bucket documents.- Specified by:
andOutputin classBucketOperationSupport<BucketOperation,BucketOperation.BucketOperationOutputBuilder> - Parameters:
expression- the SpEL expression, must not be null or empty.- Returns:
- never null.
-
andOutput
Description copied from class:BucketOperationSupportCreates a newBucketOperationSupportgiven fieldName to add an output field to the resulting bucket documents.BucketOperationSupportexposes accumulation operations that can be applied to fieldName.- Specified by:
andOutputin classBucketOperationSupport<BucketOperation,BucketOperation.BucketOperationOutputBuilder> - Parameters:
fieldName- must not be null or empty.- Returns:
- never null.
-