Python ';命令光标';对象不可下标

Python ';命令光标';对象不可下标,python,mongodb,pymongo-3.x,Python,Mongodb,Pymongo 3.x,当我运行这段代码时,我得到一个错误“CommandCursor”对象不可下标 pymongo版本=3.3.0 try: myresults = students.aggregate([{"$unwind":"$scores"},{"$match":{"scores.type":"homework"}},{"$group":{"_id":"$_id","minitem":{"$min":"$scores.score"}}}],useCursor=False) for result

当我运行这段代码时,我得到一个错误“CommandCursor”对象不可下标 pymongo版本=3.3.0

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

我从myresult['result']中删除了结果,结果成功了

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"]}}})
except Exception as e:
    raise

当useCursor为True时,聚合查询返回游标,否则返回列表。所以,您应该通过循环结果来处理聚合结果