Reputation: 139
Can the Dashboard time range be used inside a query variable with MongoDB?
I want to extract the values of a variable of the data only inside the Time Range from the dashboard, but it seems that the global variabled corresponding to the Time-Range ($from, $to etc.) are not usable inside a query variable.
The Grafana documentation says about time range inside variables:
On Time Range Change - Queries the data source when the dashboard time range changes. Only use this option if your variable options query contains a time range filter or is dependent on the dashboard time range.
From that, I assume that it can be used, but not with MongoDB.
Any inside on how can this be solved? MongoDB query variables are incompatible with Time Range intervals?
Thanks in advance.
Upvotes: 1
Views: 10080
Reputation: 139
I solved the issue. For some reason, $from and $to can be used in queries inside panels but not in variables of type query. But there exists some global variables equivalent to those, $__from and $__to that can be used (https://grafana.com/docs/grafana/latest/variables/variable-types/global-variables/).
Now, I have had problems comparing those variables to dates, my workaround was creating a new variable for each and transforming them to ms with the $toLong function, as comparing dates directly did not work.
Hope it helps someone.
Upvotes: 2