I have a collection as below :
sample
{'_id': {'day': '2020-12-04', 'device': {'device': 'DH002'}},
'value': {'average': 44.5, 'max': 50, 'min': 38}}
Issue a: Am trying to query this collection basis the date range inputted by user.The query is as below.The issue is that I get output only for the start date instead of the entire range upto the end date. Not sure what is wrong.
Issue b. If I wanted to add Device id as another query parameter,how can i do it..
extract = list( weather_dbh.dailyreports.aggregate([
{ "$match": {
"$expr": {
"$and": [
{
"$gte": [
{ "$dateFromString": { "dateString": "$_id.day", "format": "%Y-%m-%d" }},
start
]
},
{
"$lt": [
{ "$dateFromString": { "dateString": "$_id.day", "format": "%Y-%m-%d" }},
end
]
}
]
}
}}
]))
question from:
https://stackoverflow.com/questions/65860476/pymongo-aggregate-date-range-query-with-date-as-string 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…