PyMongo聚合不适用于$ max运算符

问题描述 投票:0回答:2

我的查询在mongo shell上运行正常。但是当通过pymongo运行时给出错误。有人可以帮我吗?

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" } 
    }}
     ])

但是,我收到一个错误,表示为>>

pymongo.errors.OperationFailure: unknown operator: $max

我的查询在mongo shell上运行正常。但是当通过pymongo运行时给出错误。有人可以帮我这个忙吗? db.collectioname.aggregate([{“” $ match“:{” $ and“:[...

python mongodb pymongo flask-pymongo
2个回答
0
投票

我尝试过;这对我来说可以。您能否确认此示例代码有效。如果没有,则显示完整的堆栈跟踪。


0
投票

完整的堆栈跟踪如下:

© www.soinside.com 2019 - 2024. All rights reserved.