[
{$match: {
$and: [
{"_id": {"$ne": null}}
[[ {{ filterGender }} ]]
[[ {{ filterEvent }} ]]
[[ {{ filterState }} ]]
[[ {{ filterOffice }} ]]
]
}}
, {$project: {
_id: NumberInt(0)
, childsAge: '$test'
}}
, {$addFields: {
age: {$switch:
{
branches: [
{case: {$and: [{$lt: ['$childsAge', 365]}, {$gte: ['$childsAge', 0]}] }, then: '< 1'}
, {case: {$and: [{$lt: ['$childsAge', 1825]}, {$gte: ['$childsAge', 365]}] }, then: '< 5'},
{case: {$and: [{$gte: ['$childsAge', 0]}] }, then: 'Total'}
]
}}
}}
, {$project: {
_id: NumberInt(0)
, age: '$age'
}}
, {$group: {
_id: { age: '$age'}
, totalCount: {$sum: NumberInt(1)}
}}
, {$project: {
_id: NumberInt(0)
, 'Category': '$_id.age'
, 'Count': '$totalCount'
}}
]
Here, in last switch case condition, didn't getting all the values childsAge >=0 . It's removing the previous two cases value & showing the rest. Ex: 0>=childsAge>365 has 5 data, 365>=childsAge>1825 has 4 data, and total data is 15. instead of showing 15, Total is showing 15-(5+4) = 6. How can I get 15 for Total?