@Override public AggregationPipeline bucketAuto(final String field, final int bucketCount) { return bucketAuto(field, bucketCount, new BucketAutoOptions()); }
@Override public AggregationPipeline bucketAuto(final String field, final int bucketCount, final BucketAutoOptions options) { if (bucketCount < 1) { throw new RuntimeException("bucket count should be more than 0"); } DBObject dbObject = options.toDBObject(); dbObject.put("groupBy", "$" + field); dbObject.put("buckets", bucketCount); stages.add(new BasicDBObject("$bucketAuto", dbObject)); return this; }
new BucketAutoOptions() .granularity(BucketAutoOptions.Granularity.POWERSOF2) .output("authors") .addToSet("author") .output("count") .sum(1)) .aggregate(BooksBucketResult.class);