Du kan bruge $switch
aggregering i stedet.
Schedul.aggregate([
{ "$match": { "flag": 1 }},
{ "$project": {
"name": "$name",
"day_of_week": {
"$switch": {
"branches": [
{ "case": { "$eq": ["$day_of_week", 0] }, "then": "Sunday" },
{ "case": { "$eq": ["$day_of_week", 1] }, "then": "Monday" },
{ "case": { "$eq": ["$day_of_week", 2] }, "then": "Tuesday" },
{ "case": { "$eq": ["$day_of_week", 3] }, "then": "Wednesday" },
{ "case": { "$eq": ["$day_of_week", 4] }, "then": "Thrusday" },
{ "case": { "$eq": ["$day_of_week", 5] }, "then": "Friday" }
],
"default": "Saturday"
}
}
}}
])