I have a collection in my database and I have managed to write an aggregation pipeline that returns this kind of results:
ip, type, count
where ip, type
are the fields I grouped by and count
the number of these pairs found in my collection.
How can I now only keep the pairs ip, type
where count
is maximum for all ips?
e.g.
ip1, type1, 10
ip1, type2, 20
ip1, type3, 30
ip2, type1, 30
ip2, type2, 10
From these 3, I only want to keep ip1, type3 because 30 is the max for all types of ip1 and ip2, type1 because 30 is max for all types of ip2.