How to apply dashboard filter on results and not on native query?

I am new to Metabase and trying to query MongoDB. Now that I am able to write a complex native query to get what I needed, I wanted to filter in dashboard. However, looks like I have to use variables in the Query itself.

Is it possible to filter the query results rather modifying the query using variable?

Hi @selvavm
Not without using the Native question as a base (Saved Question) for a new question, which has some limitation:
https://www.metabase.com/docs/latest/users-guide/custom-questions.html#picking-your-starting-data
So if you are seeing one of those limitations, then you need to use variables:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html

Thanks @flamber . I am okay with using a variable but it shows me “filter widget type is None”. Any idea why?

My underlying variable is a number

@selvavm Make sure the Field Type is one of these:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#creating-sql-question-filters-using-field-filter-variables

Thanks @flamber. I didn’t know numbers where not supported. I changed the types and now I can see that the drop down shows Category. Now facing with a different issue.

[
    {
        "$match": {
            "my_var": {{a}}
        }
    },
]

This is returning no results even if I type “iteration_1” in the filter textbox. However If I change the query like below it works.

[
    {
        "$match": {
            "my_var": "iteration_1"
        }
    },
]

Any idea why?

@selvavm Please read the documentation carefully. When using Field Filters, you don’t include the column in the query, since you have defined that in the sidebar:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#the-field-filter-variable-type

1 Like

Thanks and sorry. I thought both lines are same until you pointed it. Again, thanks a lot