'Group by multiple fields using mongodb aggregate builders in java application
I am fetching data from mongodb and doing some operations using aggregates builders in my java application. I was able to group by single field using the below piece of code.
Bson group = group("$city", sum("totalPop", "$pop"));
Bson project = project(fields(excludeId(), include("totalPop"), computed("city", "$_id")));
List<Document> results = zips.aggregate(Arrays.asList(group, project)).into(new ArrayList<>());
Now I need to group by using multiple fields...say city and location. Can someone help on this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
