[英]'AsyncIOMotorLatentCommandCursor' object is not subscriptable
I am working with motorclient and i have the following query where i want get the average rating of an certain user.我正在与 motorclient 合作,我有以下查询,我想在其中获得某个用户的平均评分。
res = apps.db.rating.aggregate({
"$group": {
"_id": ObjectId(user_id),
"avg_rating": {"$avg": "$rating"}
}
})
then while i am trying to extract that average value like print('avg rating', res['avg_rating'])
然后当我试图提取该平均值时,如
print('avg rating', res['avg_rating'])
this raise an error TypeError: 'AsyncIOMotorLatentCommandCursor' object is not subscriptable
这会引发错误
TypeError: 'AsyncIOMotorLatentCommandCursor' object is not subscriptable
I have googled a lot already but i didn't found solution of how i can extract a resutl from an aggregate query using motor
.我已经用谷歌搜索了很多,但我没有找到如何使用
motor
从聚合查询中提取结果的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.