Syntax:
{$project: {
columnName: {
$switch: {
branches: [
{
case:
<your-expression>,
then:
<your-expression>
}
],
default: <optional,
your-expression>
}
}
}}
Example
db.customers.aggregate([{
$project: {
customer: {
$switch: {
branches: [
{
case: {$eq: ["$Id", 0]},
then: "Zero!"
}
],
default: "do something else!"
}
}
}
}])
For more detail, go to links