I have a MongoDB collection and I need to find each distinct value in a field, and how many times each value occurs, a bit like the GROUP BY and COUNT functions in SQL.
e.g.
Item name ------ count
Soap ----------- 7
Apples --------- 4
Tin Foil ------- 5
I'm new to MongoDB and haven't really been able to find any documentation that can help me with this. So far, I've been able to return a list of distinct values, but not the count of each one.
I need to do this through the Java MongoDB library.