here is my data in mongodb:
{
"data": {
"order_goods": [{
"category": 235
}, {
"category": 666
}]
}
}, {
"data": {
order_goods: [{
"category": 235
}]
}
}
here is my expected output:
{"category":235, "total":2}
{"category":666, "total":1}
I have try many ways about aggregate such as $group
, but result always like:
{ "_id" : [ 235, 666 ], "total" : 1 }
{ "_id" : [ 235 ], "total" : 1 }
Thanks for your help.
please try the below query :