2017-06-19 38 views
0

当运行该代码,我得到一个错误“CommandCursor”对象不是标化的 pymongo版本= 3.3.0“CommandCursor”对象不是标化的

try: 
    myresults = students.aggregate([{"$unwind":"$scores"},{"$match":{"scores.type":"homework"}},{"$group":{"_id":"$_id","minitem":{"$min":"$scores.score"}}}],useCursor=False) 
    for result in myresults['result']: 
     scores.update({"_id":result["_id"]},{"$pull":{"scores":{"score": result["minitem"]}}}) 
except Exception as e: 
    raise 

回答

0

我删除的结果从myresult ['结果“]和它的工作

try: 
myresults = students.aggregate([{"$unwind":"$scores"},{"$match":{"scores.type":"homework"}},{"$group":{"_id":"$_id","minitem":{"$min":"$scores.score"}}}],useCursor=False) 
for result in myresults: 
    students.update({"_id":result["_id"]},{"$pull":{"scores":{"score": result["minitem"]}}}) 

除了例外为e: 加注

0

集合体查询时,将UseCursor为True返回游标,otherw ise名单。所以你应该通过循环结果来处理聚合结果。