{"action":"closed","issue":{"url":"https://api.github.com/repos/JamesOsgood/mongodb-grafana/issues/10","repository_url":"https://api.github.com/repos/JamesOsgood/mongodb-grafana","labels_url":"https://api.github.com/repos/JamesOsgood/mongodb-grafana/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/JamesOsgood/mongodb-grafana/issues/10/comments","events_url":"https://api.github.com/repos/JamesOsgood/mongodb-grafana/issues/10/events","html_url":"https://github.com/JamesOsgood/mongodb-grafana/issues/10","id":326294378,"node_id":"MDU6SXNzdWUzMjYyOTQzNzg=","number":10,"title":"Support multiple metrics in one query","user":{"login":"itomaldonado","id":8411264,"node_id":"MDQ6VXNlcjg0MTEyNjQ=","avatar_url":"https://avatars1.githubusercontent.com/u/8411264?v=4","gravatar_id":"","url":"https://api.github.com/users/itomaldonado","html_url":"https://github.com/itomaldonado","followers_url":"https://api.github.com/users/itomaldonado/followers","following_url":"https://api.github.com/users/itomaldonado/following{/other_user}","gists_url":"https://api.github.com/users/itomaldonado/gists{/gist_id}","starred_url":"https://api.github.com/users/itomaldonado/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itomaldonado/subscriptions","organizations_url":"https://api.github.com/users/itomaldonado/orgs","repos_url":"https://api.github.com/users/itomaldonado/repos","events_url":"https://api.github.com/users/itomaldonado/events{/privacy}","received_events_url":"https://api.github.com/users/itomaldonado/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-05-24T21:04:37Z","updated_at":"2018-08-11T06:50:13Z","closed_at":"2018-08-11T06:50:13Z","author_association":"NONE","body":"I was trying to support multiple data (metrics) in a single query, but I saw the code doesn't support it right now.\r\n\r\nHere is an example:\r\n\r\nData:\r\n```\r\n{\"_id\": <some id>, \"type\": \"type1\", \"ts\": someTS}\r\n{\"_id\": <some id>, \"type\": \"type1\", \"ts\": someTS}\r\n{\"_id\": <some id>, \"type\": \"type2\", \"ts\": someTS}\r\n{\"_id\": <some id>, \"type\": \"type3\", \"ts\": someTS}\r\n```\r\n\r\nYou do an aggregation grouping on both TS *and* the type and count them:\r\n```\r\n{\"$group\":{\"_id\":{\"type\":\"$type\",\"ts\":\"$ts\"}},\"count\":{\"$sum\":1.0}}}\r\n```\r\n\r\nAnd finally you use the project:\r\n\r\n```\r\n{\"$project\":{\"name\":\"$_id.type\",\"value\":\"$count\",\"ts\":\"$_id.ts\"}}\r\n```\r\n\r\nMongo will return something like:\r\n```\r\n[\r\n  {  \"name\": \"type1\",\r\n      \"ts\": someTS,\r\n      \"value\": 2\r\n  },\r\n  {  \"name\": \"type2\",\r\n      \"ts\": someTS,\r\n      \"value\": 1\r\n  },\r\n  {  \"name\": \"type3\",\r\n      \"ts\": someTS,\r\n      \"value\": 1\r\n  }\r\n]\r\n```\r\n\r\nSo the server should parse this and respond with data like:\r\n\r\n```\r\n...\r\n\"response\": [\r\n  {  \"target\": \"type1\",\r\n      \"datapoints\": [ [2,someTS] ]\r\n  },\r\n  {  \"target\": \"type2\",\r\n      \"datapoints\": [ [1,someTS] ]\r\n  },\r\n  {  \"target\": \"type3\",\r\n      \"datapoints\": [ [1,someTS] ]\r\n  },\r\n]\r\n```\r\n\r\nThis will force Grafana to have a metric line *per* target, which is great for these types of aggregation (e.g. count students per schools per state, count of purchases per person per store etc...)\r\n\r\nI have some changes that can be done to do this, if you want I can go ahead and implement them and raise a PR?\r\n"}}
{"actor":{"display_login":"JamesOsgood"}}