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
Modifier and TypeClassDescriptionstatic class
BucketOperationSupport.OutputBuilder
implementation forBucketAutoOperation
.static class
BucketOperationSupport.ExpressionBucketOperationBuilderSupport
implementation forBucketAutoOperation
using SpEL expression basedBucketOperationSupport.Output
.static enum
Supported MongoDB granularities.static interface
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
ConstructorDescriptionBucketAutoOperation
(AggregationExpression groupByExpression, int buckets) Creates a newBucketAutoOperation
given agroup-by expression
.BucketAutoOperation
(Field groupByField, int buckets) Creates a newBucketAutoOperation
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 BucketAutoOperation
Implementation hook to create a new bucket operation.org.bson.Document
toDocument
(AggregationOperationContext context) withBuckets
(int buckets) Configures a number of bucket buckets and return a newBucketAutoOperation
.withGranularity
(BucketAutoOperation.Granularity granularity) Configuresgranularity
that 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, 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
-
BucketAutoOperation
Creates a newBucketAutoOperation
given agroup-by field
.- Parameters:
groupByField
- must not be null.buckets
- number of buckets, must be a positive integer.
-
BucketAutoOperation
Creates a newBucketAutoOperation
given 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:
toDocument
in interfaceAggregationOperation
- Overrides:
toDocument
in classBucketOperationSupport<BucketAutoOperation,
BucketAutoOperation.BucketAutoOperationOutputBuilder> - 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
.
-
withBuckets
Configures a number of bucket buckets and return a newBucketAutoOperation
.- Parameters:
buckets
- must be a positive number.- Returns:
- new instance of
BucketAutoOperation
.
-
withGranularity
Configuresgranularity
that 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.Granularities
or provide a own one.- Parameters:
granularity
- must not be null.- Returns:
- new instance of
BucketAutoOperation
.
-
newBucketOperation
Description copied from class:BucketOperationSupport
Implementation hook to create a new bucket operation.- Specified by:
newBucketOperation
in 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: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<BucketAutoOperation,
BucketAutoOperation.BucketAutoOperationOutputBuilder> - 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
public BucketAutoOperation.BucketAutoOperationOutputBuilder andOutput(AggregationExpression expression) 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<BucketAutoOperation,
BucketAutoOperation.BucketAutoOperationOutputBuilder> - 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<BucketAutoOperation,
BucketAutoOperation.BucketAutoOperationOutputBuilder> - Parameters:
fieldName
- must not be null or empty.- Returns:
- never null.
-