Add custom date range filter on the entire dashboard cards

I need to add this filter on every card of the dashboard.

I'm using MongoDB and metabase's latest version

I got it that we can use the field filter for this. Can you suggest me how we can modify the date range query to incorporate this.

[[
  {
    "$match": {
      "$and": [
        {
          "$expr": {
            "$gte": [
              "$updatedAt", {{startdate}}
            ]
          }
        },
        {
          "$expr": {
            "$lt": [
              "$updatedAt", {{enddate}}
            ]
          }
        }
      ]
    }
  },
]]

We can set the field filter to updatedAt. How do we incorporate this in the query above?

I made this work using this

[[
  {
    "$match": {{startdate}}
  },
]]

Can you help me add another field filter optional clause?

@flamber

@Anum You only need a single Field Filter instead of two simple Date filters.

Yes, I need a single date filter and a category filter dropdown. Both should be optional clauses.

@Anum I would strongly recommend that you read the Mongo documentation, so you have a better understanding of how Mongo works and how to create queries.

[[
  {
    "$match": {
      "$and": [
        {{field_date}},
        {{field_category}}
      ]
    }
  },
]]

@flamber, one of the filters is working at a time. Not both and yes i have tried this syntax. This is not working.

@Anum I don't understand your question. I don't think Metabase can do what you want.

See if I write only 1 field filter in the query, it fetches me the result.


Now, if I add the other one, the filter doesn't work. ALthough it should work when one value is given or when both are given.

@Anum Then set the filters as Required:

This is what worked. Sharing the solution so that others can get benefit.

[[
  {
    "$match": {
      "$and": [
        {{name}}
      ]
    }
  },
]]
[[
  {
    "$match": {
      "$and": [
        {{Daterange}}
      ]
    }
  },
]]