mongo客户端升级导致pymongo中使用聚合函数时出现异常
程序员文章站
2023-03-26 17:35:10
一.异常信息 二.解决办法 ......
一.异常信息
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)