当前位置: 移动技术网 > IT编程>脚本编程>Python > mongo客户端升级导致pymongo中使用聚合函数时出现异常

mongo客户端升级导致pymongo中使用聚合函数时出现异常

2020年01月14日  | 移动技术网IT编程  | 我要评论

首席夜话 郭敬明,南充职业技术学院录取查询,aff男友

一.异常信息

the 'cursor' option is required, except for aggregate with the explain argument

二.解决办法

#部分源代码错误代码
pipeline = [
    {"$match": {
        "updatetime": {
            "$gte":(datetime.datetime(year,month,day, 0, 0, 0, 000) - datetime.timedelta(hours=8)),
            "$lte":(datetime.datetime(year,month,day, 23, 59, 59, 000) - datetime.timedelta(hours=8))},
        "type": self.type}},
    {"$group": {"_id": {"platformname": "$platformname"}, "count": {"$sum": 1}}},
    {"$match": {"count": {"$gt": 1}}}]
every_zb_num = self.db_data.command('aggregate', self.tablename, pipeline=pipeline,allowdiskuse=true)


#解决办法添加游标
pipeline = [
    {"$match": {
        "updatetime": {
            "$gte":(datetime.datetime(year,month,day, 0, 0, 0, 000) - datetime.timedelta(hours=8)),
            "$lte":(datetime.datetime(year,month,day, 23, 59, 59, 000) - datetime.timedelta(hours=8))},
        "type": self.type}},
    {"$group": {"_id": {"platformname": "$platformname"}, "count": {"$sum": 1}}},
    {"$match": {"count": {"$gt": 1}}}]
#在执行的时候添加游标参数
every_zb_num = self.db_data.command('aggregate', self.tablename,cursor = {}, pipeline=pipeline,allowdiskuse=true)
 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网