meln5674 / grafana-mongodb-community-plugin

Open Source Grafana Plugin for querying MongoDB
GNU Affero General Public License v3.0
137 stars 18 forks source link

How to use the time range in the query? #16

Closed danieleds closed 1 year ago

danieleds commented 1 year ago

Great plugin!

I'm trying to understand how to use from and to in my query.

Using https://github.com/JamesOsgood/mongodb-grafana, I could use $from and $to to only return the data in the time range specified by the user, but I can't seem to find an equivalent way with this plugin. Is this supported?

meln5674 commented 1 year ago

$to, $from, and the rest of the built-in variables, as well as any variables defined by specific dashboards are all supported. As well, if you are using the timeseries query type and your timestamp field is a standard ISODate, there is an option to inject the time filtering automatically for you.

danieleds commented 1 year ago

Nice, thanks! Just started using Grafana, and I missed that.

For future reference, I was able to use the following snippet into my queries: { "$toDate": "${__from:date}" } / { "$toDate": "${__to:date}" } (takes the string and performs the conversion to a Date type)