Conditional query? (mongodb)

So I have a little trouble with a my searchEngine logic.

Im trying to write a conditional query based on whether I want the "alias" key involved or not.

My condition looks like this. Hoever it does not work.

Do get results specific results, I have success with this. But it does not return all the brands when the searchfield is empty, which is what I need.

If searchfield is empty, i get no results at all

Only when my query field is empty the list display all the brands.

How can I update my query in a dynamic way?

If brandOfficeSearchField.value has a valid alias string show it, if not, show me the the entire list.

Solved it
{{ brandOfficeSearchField.value ? { "alias": brandOfficeSearchField.value } : {} }}

1 Like