Module spring.data.mongodb
Class BucketAutoOperation
java.lang.Object
org.springframework.data.mongodb.core.aggregation.BucketOperationSupport<BucketAutoOperation,BucketAutoOperation.BucketAutoOperationOutputBuilder>
org.springframework.data.mongodb.core.aggregation.BucketAutoOperation
- All Implemented Interfaces:
AggregationOperation,FieldsExposingAggregationOperation
public class BucketAutoOperation
extends BucketOperationSupport<BucketAutoOperation,BucketAutoOperation.BucketAutoOperationOutputBuilder>
implements FieldsExposingAggregationOperation
Encapsulates the aggregation framework
Bucket stage is typically used with
We recommend to use the static factory method
$bucketAuto-operation. Bucket stage is typically used with
Aggregation and $facet. Categorizes incoming documents into a
specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically
determined in an attempt to evenly distribute the documents into the specified number of buckets. We recommend to use the static factory method
Aggregation.bucketAuto(String, int) instead of creating
instances of this class directly.- Since:
- 1.10
- Author:
- Mark Paluch, Christoph Strobl
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBucketOperationSupport.OutputBuilderimplementation forBucketAutoOperation.static classBucketOperationSupport.ExpressionBucketOperationBuilderSupportimplementation forBucketAutoOperationusing SpEL expression basedBucketOperationSupport.Output.static enumSupported MongoDB granularities.static interfaceNested 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
ConstructorsConstructorDescriptionBucketAutoOperation(AggregationExpression groupByExpression, int buckets) Creates a newBucketAutoOperationgiven agroup-by expression.BucketAutoOperation(Field groupByField, int buckets) Creates a newBucketAutoOperationgiven 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 BucketAutoOperationImplementation hook to create a new bucket operation.org.bson.DocumenttoDocument(AggregationOperationContext context) withBuckets(int buckets) Configures a number of bucket buckets and return a newBucketAutoOperation.withGranularity(BucketAutoOperation.Granularity granularity) Configuresgranularitythat specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10 and return a newBucketAutoOperation.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
-
BucketAutoOperation
Creates a newBucketAutoOperationgiven agroup-by field.- Parameters:
groupByField- must not be null.buckets- number of buckets, must be a positive integer.
-
BucketAutoOperation
Creates a newBucketAutoOperationgiven agroup-by expression.- Parameters:
groupByExpression- must not be null.buckets- number of buckets, must be a positive integer.
-
-
Method Details
-
toDocument
Description copied from interface:AggregationOperation- Specified by:
toDocumentin interfaceAggregationOperation- Overrides:
toDocumentin classBucketOperationSupport<BucketAutoOperation,BucketAutoOperation.BucketAutoOperationOutputBuilder> - 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.
-
withBuckets
Configures a number of bucket buckets and return a newBucketAutoOperation.- Parameters:
buckets- must be a positive number.- Returns:
- new instance of
BucketAutoOperation.
-
withGranularity
Configuresgranularitythat specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10 and return a newBucketAutoOperation.
Use either predefinedBucketAutoOperation.Granularitiesor provide a own one.- Parameters:
granularity- must not be null.- Returns:
- new instance of
BucketAutoOperation.
-
newBucketOperation
Description copied from class:BucketOperationSupportImplementation hook to create a new bucket operation.- Specified by:
newBucketOperationin classBucketOperationSupport<BucketAutoOperation,BucketAutoOperation.BucketAutoOperationOutputBuilder> - Parameters:
outputs- the outputs- Returns:
- the new bucket operation.
-
andOutputExpression
public BucketAutoOperation.ExpressionBucketAutoOperationBuilder 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<BucketAutoOperation,BucketAutoOperation.BucketAutoOperationOutputBuilder> - Parameters:
expression- the SpEL expression, must not be null or empty.params- must not be null- Returns:
- new instance of
BucketOperationSupport.ExpressionBucketOperationBuilderSupportto createBucketOperation.
-
andOutput
public BucketAutoOperation.BucketAutoOperationOutputBuilder andOutput(AggregationExpression expression) Description copied from class:BucketOperationSupportCreates a newBucketOperationSupportgiven anAggregationExpressionto add an output field to the resulting bucket documents.- Specified by:
andOutputin classBucketOperationSupport<BucketAutoOperation,BucketAutoOperation.BucketAutoOperationOutputBuilder> - 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<BucketAutoOperation,BucketAutoOperation.BucketAutoOperationOutputBuilder> - Parameters:
fieldName- must not be null or empty.- Returns:
- never null.
-