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

No support for variables input in aggregation pipeline #21

Closed lpnc closed 1 year ago

lpnc commented 1 year ago

Simply a very powerful feature not suported yet... ...Or is it just me doing something wrong?

yar2001 commented 1 year ago

According to my experiments, you can directly use ${xxx} to denote the variable value. For example, if there is a variable called uid and is a number, the aggregate code should be:

 {
    "$match": {
      "createdAt": {
        "$gte": {
          "$date": "${__from:date}"
        },
        "$lte": {
          "$date": "${__to:date}"
        }
      },
      "uid": ${uid:int}
    }
  }

Ignore the error in the json, when the plugin query to the backend, it will automatically replace ${uid:int} with number

meln5674 commented 1 year ago

This plugin supports the standard grafana syntax for variables, and will automatically handle inserting them into the JSON, as the above post describes. If you have a specific query that is not replacing variables, please post it here along with versions of grafana and the plugin, and I will try to reproduce. Otherwise, I will close this as not an issue in a few days if I don't hear back.