I'm having trouble to write that query in Java using springframework.
db.getCollection('fish').aggregate(
{$match : {"uploadDate" : { $gte : new ISODate("2017-05-22T00:00:00Z"), $lte : new ISODate("2017-05-25T00:00:00Z") }}},
{$group: {_id: {lake : "$lake", type : "$type"}, count: {$sum: 1}}} ,
{$project: {array : ["$_id.type" , "$count"], count : "$count"}},
{$group: {_id: {lake : "$_id.lake"}, count: {$sum: 1}, types : {$addToSet : "$array"}}})
I was able to write match and group but I'm having trouble to add project that has array containing both id.type and count. So far I was able to write this
Aggregation aggregation = newAggregation(match(Criteria.where("uploadDate").gte(created).lte(newCreatedDate)),
group("lake").count().as("values"));
I couldn't find any solution how to write it and I only see that you can add Fields/Strings to project().