I have issue with the following query… Unable to get count correctly… i wanted to have unique count of mhoId
db.getCollection('billing_info').aggregate(
[
{
"$match": {
"billing.receiptinfo.receipt_date": {
"$gte": "2020-04-01",
"$lte": "2020-04-25"
},
"billing.receiptinfo.payment_mode": {
"$nin": [
"",
[]
]
},
"billing.receiptinfo.payment_submitted": {
"$lt": 1
},
"billing.receiptinfo.mho_id": {
"$nin": [
null,
""
]
}
}
},
{
"$unwind": "$billing.receiptinfo"
},
{
"$facet": {
"orderDetails": [
{
"$project": {
"billId": "$billing.billinginfo.billingid",
"orderId": "$billing.billinginfo.order_did",
"mhoId": "$billing.receiptinfo.mho_id",
"mhoName": "$billing.receiptinfo.mho_name"
}
},
{
"$group": {
"_id": {
"mhoId": "$mhoId"
},
"info": {
"$push": "$$ROOT"
}
}
}
],
"countOrder": [
{
"$group": {
"_id": "$mhoId",
"count": {
"$sum": 1
}
}
}
]
}
}
])