I have a mongo aggregate query which calculates COUNT, MIN, MAX and BLANK counts of different keys.
db.getCollection('ReportTestProcess').aggregate([
$group": {
"_id":0,
"Inititated_on_MIN": {
"$min": "$Inititated_on.v"
},
"Inititated_on_MAX": {
"$max": "$Inititated_on.v"
},
"Text_COUNT":{$sum:1},
"Text_BLANK": {
"$sum": {
"$cond": [
{
"$ifNull": [
"$Inititated_on.v",
false
]
},
0,
1
]
}
}
}])
Now I want UNIQUE_COUNT of elements along with it. The only way I could think of doing it is to group based the fields but grouping will affect the results of MIN, MAX or COUNT
_idexpression in the$groupstage here? and what is theTexthere?$addToSethere,{ "UNIQUE_TEXT": { "$addToSet": "YOUR_FIELD" }}and then use one$projectstage to find the length of theUNIQUE_TEXTarray or either use$facetaggregation