The document has an array field and each of them has a unique Id field. After doing unwind on the array, I need to add a count field on each array document instead of Id. The count should be the sum of similar array fields (grouped by fields other than Id).
Sample document - https://mongoplayground.net/p/LUPqVw07unP
Expected result:
{
"originId": 123,
"taskMetric": {
"count": 2,
"status": "OPEN",
"assignee": "ABC"
}
}, {
"originId": 1,
"taskMetric": {
"count": 1,
"status": "COMPLETED",
"assignee": "CDE"
}
}, {
"originId": 1,
"taskMetric": {
"count": 1,
"status": "COMPLETED",
"assignee": "EFG"
}
}