Create a Variable of Query type from MongoDB source

I would like to define a Variable of Query type from the MongoDB data source.
For this reason, I created a sample database trial_db and a table trial_table, with the following items:

[{
  "name": "A",
  "value": 5.3
},{
  "name": "A",
  "value": 5.8
},{
  "name": "A",
  "value": 6.2
},{
  "name": "B",
  "value": 6.8
},{
  "name": "B",
  "value": 1.2
}]

I would like to create a Grafana Variable from the distinct name fields (A and B in this case).
So, in the Query field of this variable, I selected the MongoDB data source, and inserted trial_db.trial_table.distinct("name") as query. It is not working: the “Preview of values” is None. And in the dashboard, the new variable appears, but I can only select None. So, this variable is not working, and I suspect that I am somehow misusing the MongoDB data source for this use case.

The MongoDB plugin works very well as a data source for panels, but it is not working for the definition of Variables.

What should I do? Is the MongoDB plugin supposed to work for the definition of Variables?

I am using Grafana 9.1.5.

1 Like

I’m currently evaluating the plugin for usage within our company and I’m experiencing the same behaviour. Seems like the mongodb datasource is not capable to serve multiple values for Dashboard Variables so they can be filtered to Names and Values after that using the regex field?