If else if cond in mongodb aggregation If else if cond in mongodb aggregation mongoose mongoose

If else if cond in mongodb aggregation


You can use $switch aggregation instead.

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"      }    }  }}])