1

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you give us more details on the how-to? Thx.
Unfortunetly I don't have access to the code anymore. But as I recall, I could not compare directly the variables $__from and $__to with the time variable from my data so I had to make a workaround and create a new variable that transformed $__from and $__to to Long with the $toLong function and then I could compare those variables to the time from the data. As far as I know, this was something unique to MongoDB and looked like a bug to me, I haven't had this problem with other databases. Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.