I need your help for using MongoDB aggregation framework with java driver. I don\'t understand how to write my request, even with this documentation.
I want to get t
Here is a simple way to count employee by departmentId.. Details at: Aggregation using Java API
Map empCountMap = new HashMap<>();
AggregateIterable iterable = getMongoCollection().aggregate(Arrays.asList(
new Document("$match",
new Document("active", Boolean.TRUE)
.append("region", "India")),
new Document("$group",
new Document("_id", "$" + "deptId").append("count", new Document("$sum", 1)))));
iterable.forEach(new Block() {
@Override
public void apply(final Document document) {
empCountMap.put((Long) document.get("_id"), (Integer) document.get("count"));
}
});