आपको एक अतिरिक्त $match
चाहिए
पाइपलाइन चरण जो एम्बेडेड फ़ील्ड के आधार पर आने वाले दस्तावेज़ों को फ़िल्टर करेगा "$productAttribute.colour"
मौजूदा और शून्य नहीं:
db.productMetadata.aggregate([
{
"$match": {
"productAttribute.colour": {
"$exists": true,
"$ne": null
}
}
},
{
"$group": {
"_id": {
"color": "$productAttribute.colour",
"gender": "$productAttribute.gender"
},
"count": {
"$sum": 1
}
}
}
]);