Menu

Azure Cosmos DB query editor

Grafana provides a query editor for Azure Cosmos DB, which allows you to create and execute Azure Cosmos DB queries.

Query

  • Database - Select a database
  • Container - After a database has been selected, select a container
  • Partition Key - Enter a partition key to make a single partition query. Leave this field empty to make a multi partition query with limitations. See Known limitations
  • Query - Enter a Cosmos DB NoSQL query. Refer to Queries in Azure Cosmos DB for NoSQL for more information on writing queries. Multi partition queries are not supported with these keywords: TOP ORDER BY OFFSET LIMIT Aggregates DISTINCT GROUP BY. To query a single partition set the Partition Key field.

Macros

To simplify syntax and to allow for dynamic parts, like date range filters, the query can contain macros.

Here is an example of a query with a macro that will use Grafana’s time filter:

sql
SELECT c.date_time, c.data_stuff
FROM c
WHERE $__timeFilter(c.date_time)
  • $__timeFilter(columnName) - Replaced by a conditional that filters the data (using the provided column) based on the time range of the panel. Output example: columnName >= '2024-05-10T16:00:00Z' AND columnName <= '2024-05-10T17:00:00Z'
  • $__fromTime(columnName) - Replaced by a conditional that filters the data (using the provided column) based on the from time of the panel. Output example: columnName >= '2024-05-10T16:00:00Z'
  • $__toTime(columnName) - Replaced by a conditional that filters the data (using the provided column) based on the to time of the panel. Output example: columnName <= '2024-05-10T16:00:00Z'