Closed Kromtar closed 1 year ago
Yes, the start and end dates are provided as the $__from
and $__to
variables which can be included in your query, as described here . As well, if you use the timeseries query type, there is an option to automatically inject a $match
stage before your pipeline which uses these variables, assuming your timestamp is a standard ISODate() object.
Thank very much.
Here is an example of how to retrieve documents within a time range using Grafana's Picker. Assume that the 'timestamp' field is where we store the time record in Date format:
[{
"$match":{
"$expr":{
"$and":[
{"$gte":["$timestamp",{"$toDate":"${__from:date}"}]},
{"$lte":["$timestamp",{"$toDate":"${__to:date}"}]}
]
}
}
}]
Is there any way to incorporate the selected date range from Grafana's date picker into the aggregation query?