Mongo collection filter by boolean is not working

I want to make filtering for custom native query on mongo, and the filter is supposed to be boolean.

[
{ $match: { covid_related: {{covid_related}} } },

{"$project": { "covid_related":"$covid_related","country":"$country"}}   

]

When I pass true from the filter it gives me there is no results.

I tried toBool to be sure it's converting text to boolean, but same issue
{ $match: { covid_related: { $toBool: {{covid_related}} } }},

Also it returns no results.
But when I manually write true in the match it works.
{ $match: { covid_related: true }},
it returns data.

Can u plz explain what I am missing?

Thank yoou

Hi @alaahammouda
I'm not sure why it's not working, but you can try using a View instead, where you convert the data into the format you want to use while querying.
https://docs.mongodb.com/manual/core/views/

Is there a way to see the query with filters created to automatically filter widgets that was created using simple question not native query? Because boolean filtering is working there.

@alaahammouda You can see the query generated in the GUI by clicking "View the SQL":
https://www.metabase.com/docs/latest/users-guide/custom-questions.html#viewing-the-sql-that-powers-your-question

It works when I make it field related and here is the working code.

{ $match: { $and: [{"count":{"$gt":0}}[[, {{covid_related}} ]] [[,  {{country}} ]] ] },
1 Like