import static org.springframework.data.mongodb.core.aggregation.Aggregation.match;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.sort;
List<AggregationOperation> options = new ArrayList<AggregationOperation>();
Criteria criteria = Criteria.where("deviceID").is(deviceId).and("source").is(source).and("ppl").is(ppl);
DBObject groupFields = new BasicDBObject("ppl2","$ppl2");
DBObject groupField = new BasicDBObject("_id",groupFields);
DBObject group = new BasicDBObject("$group",groupField);
options.add(match(criteria));
options.add(new CustomOperation(group));
Aggregation aggregation = newAggregation(options);
AggregationResults<DBObject> results = mongoTemplate.aggregate(aggregation,"event_collection", DBObject.class);
List<DBObject> list = new ArrayList<>(results.getMappedResults());