Package dev.morphia.aggregation.stages
Class AutoBucket
java.lang.Object
dev.morphia.aggregation.stages.Stage
dev.morphia.aggregation.stages.AutoBucket
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.
Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound and the exclusive upper bound for the bucket, and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.
-
Method Summary
Modifier and TypeMethodDescriptionstatic AutoBucket
Creates a new auto bucketA positive 32-bit integer that specifies the number of buckets into which input documents are grouped.granularity
(BucketGranularity granularity) A string 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.An expression to group documents by.outputField
(String name, Expression value) Adds a field to the document that specifies the fields to include in the output documents in addition to the _id field.
-
Method Details
-
autoBucket
Creates a new auto bucket- Returns:
- the new bucket
- Since:
- 2.2
- MongoDB documentation
- Aggregration Pipeline Stage: $bucketAuto
- Since server release
- 3.4
-
buckets
A positive 32-bit integer that specifies the number of buckets into which input documents are grouped.- Parameters:
buckets
- the number of buckets- Returns:
- this
-
granularity
A string 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.Available only if the all groupBy values are numeric and none of them are NaN.
- Parameters:
granularity
- the granularity- Returns:
- this
-
groupBy
An expression to group documents by.- Parameters:
groupBy
- the expression to use- Returns:
- this
-
outputField
Adds a field to the document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions.- Parameters:
name
- the new field namevalue
- the value expression- Returns:
- this
-