__timeFrom/__timeTo macros in MongoDB plugin

  • What Grafana version and what operating system are you using?

Grafana v9.2.2 at Grafana Cloud.

MongoDB data source for Grafana v1.4.9

  • What are you trying to achieve?

I’m trying to make my stats dashboards being adapatable to the globally specified time range.

  • How are you trying to achieve it?

I’m using __timeFrom and __timeTo macros provided by MongoDB plugin. Here’s my query:

my_db.mycollection.find({"datetime": {$gt: $__timeFrom, $lt: $__timeTo}})

datetime is a field in ISODate format.

  • What happened?

The above-mentioned query results in the following error: “error parsing find args - error decoding key 0.datetime: invalid JSON input. Position: 48. Character: $”.

If I inspect the query, it looks as follows:

my_db.mycollection.find({"datetime": {$gt: {"$date": "2019-07-16T02:57:47Z"}, $lt: {"$date": "2021-05-03T00:00:00Z"}}})
  • What did you expect to happen?

I expected the dashboard to display data which datetime is between $__timeFrom and $__timeTo.

  • Did you follow any online instructions? If so, what is the URL?

My query is very similar to the examplr in MongoDB plugin documentation.