@Override public AggregationPipeline bucket(final String field, final List<?> boundaries, final BucketOptions options) { if (boundaries == null || boundaries.size() < 2) { throw new RuntimeException("Boundaries list should be present and has at least 2 elements"); } DBObject dbObject = options.toDBObject(); dbObject.put("groupBy", "$" + field); dbObject.put("boundaries", boundaries); stages.add(new BasicDBObject("$bucket", dbObject)); return this; }