I would like to get a summary of the count for each field for each value of a collection.
Example:
A collection may contain the following document schema and values:
{
shop: A, B, C, D
fruits: banana, apple, kiwi
region: north, south, west, east
}
Goal: I want to get a single document as a result with the count for every value like this:
{
shop: {
A: 2,
B: 5,
C: 3,
D: 1
},
fruits: {
banana: 3,
apple: 2,
kiwi: 1
}
...
}
How is that possible with mongo?
Thanks for your help!