How to use conditions inside projections.computed?

Hi,
criteria: we want to copy field name to a list when condition is met

we were trying to use $cond inside projections.computed. It is working when we pass strings/booleans as expression results, but when try to perform any function, like Arraylist.add/ remove which return boolean it is performing both.
code:
passing strings/boolean:

passing list functions as

Hi @Srujana_Bolli, Welcome to the MongoDB community forum,

It would be helpful if you post a sample document and query in regular JS syntax.

You can also specify the language tag in your post that you have posted this query. So related expert can help you.