Dependent query variables not updating (MongoDB data source)

  • What Grafana version and what operating system are you using?
    9.2.2 (Grafana Cloud)

  • What are you trying to achieve?
    Create dependent query variables using the MongoDB data source, ie. available options for variable B is dependent on variable A selection

  • How are you trying to achieve it?
    Collection contains just two documents:

   {"colour":"red",
    "shape":"square"}

   {"colour":"blue",
    "shape":"triangle"}

Query for primary/parent variable (x):

    test.tc.aggregate([
      {"\$project": {
          "_id": 0,
          "colour": 1
        }},
      {"\$group": {
          "_id": "\$colour"
        }}
    ])

…yields values red and blue as expected.

Query for dependent/child variable (y):

    test.tc.aggregate([
      {"\$match": {
          "colour": "$x"
        }},
      {"\$project": {
          "_id": 0,
          "shape": 1
        }},
      {"\$group": {
          "_id": "\$shape"
        }}
    ])
  • What did you expect to happen?
    Toggle between x values (red/blue) causes y dropdown option to update with square/triangle as appropriate

  • What happened?
    y dropdown contains either triangle or square but that value doesn’t change when x is toggled between red and blue. It seems that y dropdown option can only be changed by changing x then making a null change to y’s query, followed by a manual query rerun.

  • Can you copy/paste the configuration(s) that you are having problems with?
    See above

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No errors

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