$lookup with $match inside pipeline

So, I’d like to store permanent collection queries in another collection to later populate these with $lookup. Unfortunately, when I try to $match $$ROOT it fails no matter how I try to work this around.

Here’s what I expected to work, in a nutshell: Mongo playground

I ended up with $function to match the documents JS-way but I’m still interested if there’s a way to make the use of $match while storing the query in an object. Maybe there’s an option to “unpack” the variable into an object?

Ended up using $switch with multiple branches that cover my queries that sets a flag and then matching by this flag. This approach has an issue that I have to cover all possible queries either by a huge tree or by a series of match cases. Still wondering if there’s a better approach to this issue.
Take a look at the current result: Mongo playground