简体   繁体   English

将 Sql 查询转换为 Mongodb 查询

[英]Convert Sql query to Mongodb query

i have a query in sql that i want to convert in mongodb with python pymongo.我在 sql 中有一个查询,我想用 python pymongo 在 mongodb 中转换。

cursor=execute("select avg(id13)::numeric(10,2) from timestamppsql where timestamp1<='2011-01-01 00:05:00'")

This is the code i tested in mongodb:这是我在 mongodb 中测试的代码:

cursor=mydb1.mongodbtime.aggregate({
    '$group': {
        "timestamp1":{ "$lte" : datetime.strptime("2011-01-01 00:05:00", "%Y-%m-%d %H:%M:%S") },

        "avg_id13": {"$avg": "$id13"}
    }
})

The output is this: output 是这样的:

pipeline must be a list

How can i fix that?Any help would be appreciated.我该如何解决?任何帮助将不胜感激。

The argument to aggregate is an array, not a mapping.聚合的参数是一个数组,而不是一个映射。 Put your mapping into an array.将您的映射放入一个数组中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM