__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.

I’ve exactly the same problem were

$__timeFrom

gets replaced with

{"$date": "2024-01-26T09:09:43Z"}

but afaik with mongodb only following works:

2024-01-26T09:09:43Z

How can i use the timepicker with mongodb?
I’ve already looked threw the documentation and a few forum posts, but I cannot find a solution.

Here is my query:

n8n_datastore.monitor_testCollection.aggregate([
  {
    $match: {
      filterone: "casetwo",
      "datetime": {"$gte": "2024-01-26T09:09:43Z", "$lte": "2024-02-26T09:09:43Z"}
    }
  },
  { $count: "casetwocount" }
])