Impossible to use $switch, $and and $match for conditional queries or aggregations

Hello @Damien ,

Welcome to The MongoDB Community Forums! :wave:

The reason you are getting below error while using $match in $switch is that, the case field of $switch is expected to be any valid expression that resolves to a boolean . If the result is not a boolean , it is coerced to a boolean value. $match is not an expression (provides document as result and not a boolean value) but an aggregation stage.

Invalid $set :: caused by :: Unrecognized expression ‘$match’

I would recommend you to go through Expressions in MongoDB to learn more about what are valid expressions and how one can use them to their advantage.

Regards,
Tarun

1 Like