Gebruik deze opdracht, het zal werken voor uw voorbeeldgeval, ik hoop dat het uw probleem oplost,
db.testCollection.aggregate([{
$group: {
_id: {
ASSIGN_ID: "$ASSIGN_ID",
STATUS: "$STATUS"
},
count: {
"$sum": 1
}
}
}, {
$group: {
_id: "$_id.ASSIGN_ID",
STATUS_GROUP: {
$push: {
STATUS: "$_id.STATUS",
count: "$count"
}
}
}
}])
uitvoer in shell :
{
"_id": "583f84bce58725f76b322398",
"STATUS_GROUP": [{
"STATUS": 3,
"count": 1
}, {
"STATUS": 4,
"count": 2
}, {
"STATUS": 1,
"count": 1
}]
}, {
"_id": "583f84bce58725f76b322311",
"STATUS_GROUP": [{
"STATUS": 3,
"count": 1
}, {
"STATUS": 1,
"count": 1
}]
}, {
"_id": "583f84bce58725f76b322322",
"STATUS_GROUP": [{
"STATUS": 1,
"count": 1
}, {
"STATUS": 4,
"count": 1
}]
}