Пробовал; Он отлично работает для меня. Можете ли вы подтвердить, что этот образец кода работает? Если нет, напечатайте полную трассировку стека.
import pymongo
import datetime
offset = 0
limit = 1
organization_id = 1
stdate = datetime.datetime(2020, 1, 1, 0, 0)
enddate = datetime.datetime(2021, 1, 1, 0, 0)
db = pymongo.MongoClient()['mydatabase']
db.collectioname.insert_one({'organization_id': organization_id, 'resulttime': datetime.datetime.now(), 'temperature': 37.4})
records = db.collectioname.aggregate([
{"$match": {"$and": [
{"organization_id": int(organization_id)},
{"resulttime": {
"$gte": stdate,
"$lte": enddate
}}]}
},
{"$skip": int(offset)},
{"$limit": int(limit)},
{"$group": {
"_id": "$userid",
"max_temperature": {"$max": "$temperature"},
"min_temperature": {"$min": "$temperature"}
}}
])
print(list(records))