I have the following collection:
{'user': 'Emma', 'type': 'Apple'}
{'user': 'Emma', 'type': 'Orange'}
{'user': 'Emma', 'type': 'Orange'}
I want to get statistics for "Emma", How many records of "apples" and "oranges" there are.
For example the output:
{
'apple': 1,
'Orange': 1
}
It's very simple to do this if I split it into 2 queries. But for efficiency, I want to do it all at once.
I'm wondering if I should use $facet.