My dataset is structured like this:
{
"_id" : 1,
"category" : [
{
"name": "category1"
},
{
"name": "category2"
}
],
"event": [
{
type: "house"
},
{
type: "mouse"
}
]
},
{
"_id" : 2,
"category" : [
{
"name": "category2"
},
{
"name": "category3"
}
]
},
{
"_id" : 3,
"category" : [
{
"name": "category3"
},
{
"name": "category1"
}
],
"event": [
{
type: "mouse"
}
]
}
I am seeking assistance on grouping the distinct category names and counting events to produce a summary document like:
{ "category1": total_count: 2,
"category2": total_count: 0,
"category3": total_count: 1}
Your help in solving this would be greatly appreciated.