Filtering on a whole dashboard

Hi

I have got several charts in a dashboard that I would like to filter globally. I’d like to add a filter on dates, to view only the datas of the last day. Actually dates are stored as strings, and I convert and filter it on each chart (hardcoded) ; il would like to deport this filter on the dashboard and print it as a parameter.

If I understand this post :

Those 2 functionnalities are only available on a single chart and not on the dashboard :

Is that exact or am I missing something ?

Thanks :slight_smile:

Hi @St_ef -

When you add a dashboard filter, the types of each field will be the original type, and it doesn’t take any chart-level type conversions into account. To do what you’re looking for, you should create a “Charts View” (from the Data Sources page) that converts the string field to a date, and then use the View instead of the raw collection for each chart.

Note that while this will achieve your functional outcome, the performance may be poor if you have a lot of data, as Atlas will need to convert every string field to dates each time and it won’t be able to use any indexes. To improve the performance you should store your dates as the correct type and index the field.

HTH
Tom

2 Likes

Great @tomhollander, that’s it !

db.getCollection('mycollection').updateMany(
   {
      "mdate":{
         "$type":"string"
      }
   },
   [
      {
         "$set":{
            "mdate":{
               "$dateFromString":{
                  "dateString":"$mdate"
               }
            }
         }
      }
   ]
)

The mdate attribute is now a date and filter works !
Many thanks :slight_smile:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.