Class AutoBucket

java.lang.Object
dev.morphia.aggregation.stages.Stage
dev.morphia.aggregation.stages.AutoBucket

public class AutoBucket extends Stage
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 Details

    • autoBucket

      public static AutoBucket 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

      public AutoBucket buckets(Integer 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

      public AutoBucket 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.

      Available only if the all groupBy values are numeric and none of them are NaN.

      Parameters:
      granularity - the granularity
      Returns:
      this
    • groupBy

      public AutoBucket groupBy(Object groupBy)
      An expression to group documents by.
      Parameters:
      groupBy - the expression to use
      Returns:
      this
    • outputField

      public AutoBucket 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. To specify the field to include, you must use accumulator expressions.
      Parameters:
      name - the new field name
      value - the value expression
      Returns:
      this