Skip to content

Query Returns No Data in Grafana #43

@FractalMind

Description

@FractalMind

Issue Description:
I'm having trouble executing a MongoDB aggregation query in Grafana using this datasource plugin. I have two very similar queries:

Query that works in Appsmith:

{
  "aggregate": "users",
  "pipeline": [
    {
      "$match": {
        "CreatedOn": {
          "$gte": "2023-01-25T00:00:00Z"
        }
      }
    },
    {
      "$group": {
        "_id": {
          "$dateToString": {
            "format": "%Y-%m-%d",
            "date": {
              "$dateFromString": {
                "dateString": "$CreatedOn"
              }
            }
          }
        },
        "count": {
          "$sum": 1
        }
      }
    },
    {
      "$sort": {
        "_id": 1
      }
    },
    {
      "$project": {
        "_id": 0,
        "date": "$_id",
        "count": 1
      }
    }
  ],
  "cursor": {}
}

Query that doesn't return any data in Grafana:

[
  {
    "$match": {
      "CreatedOn": {
        "$gte": "2023-01-25T00:00:00Z"
      }
    }
  },
  {
    "$group": {
      "_id": {
        "$dateToString": {
          "format": "%Y-%m-%d",
          "date": {
            "$dateFromString": {
              "dateString": "$CreatedOn"
            }
          }
        }
      },
      "count": {
        "$sum": 1
      }
    }
  },
  {
    "$sort": {
      "_id": 1
    }
  },
  {
    "$project": {
      "_id": 0,
      "date": "$_id",
      "count": 1
    }
  }
]

Questions:

Why does the full aggregation command (including "aggregate": "users" and "cursor": {}) work well in Appsmith, but the plain pipeline array does not pull any data from the "users" collection in Grafana?

Is the Grafana plugin expecting the full aggregation command structure rather than just the pipeline because it won't work?

Could there be a syntax or format difference that I’m missing when writing queries for Grafana using this plugin?

I'm not sure what I am doing wrong. Any help or clarification on how to properly structure the query for Grafana would be greatly appreciated.

Thank you!

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions