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

一.异常信息

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)
 
posted @ 2020-01-13 16:38  小小咸鱼YwY  阅读(493)  评论(0编辑  收藏  举报