Добавление меток, включая $ switch к запросу, решило это для меня.
[
{
"$project": {
"completedAt": "$completedAt",
"status": "$status"
}
},
{
"$match": {
"$and": [
{
"status": {
"$eq": "successful"
}
},
{
"completedAt": {
"$gt": ISODate("2019-01-01")
}
}
]
}
},
{
"$project": {
"_id": "$_id",
"___group": {
"completedAt": {
"$dayOfWeek": "$completedAt"
}
}
}
},
{
"$group": {
"_id": "$___group",
"count": {
"$sum": 1
}
}
},
{
"$sort": {
"_id": 1
}
},
{
"$project": {
"_id": false,
"count": true,
"label": {
"$switch": {
"branches": [
{
"case": { "$eq": ["$_id.completedAt", 1] },
"then": "Sunday"
},
{
"case": { "$eq": ["$_id.completedAt", 2] },
"then": "Monday"
},
{
"case": { "$eq": ["$_id.completedAt", 3] },
"then": "Tuesday"
},
{
"case": { "$eq": ["$_id.completedAt", 4] },
"then": "Wednesday"
},
{
"case": { "$eq": ["$_id.completedAt", 5] },
"then": "Thursday"
},
{
"case": { "$eq": ["$_id.completedAt", 6] },
"then": "Friday"
},
{
"case": { "$eq": ["$_id.completedAt", 7] },
"then": "Saturday"
}
],
"default": "Unknown"
}
}
}
},
{
"$sort": {
"completedAt": 1
}
}
]