我正在使用motorclient,并且我有以下查询,我想在其中获得某个用户的平均评分。
res = apps.db.rating.aggregate({
"$group": {
"_id": ObjectId(user_id),
"avg_rating": {"$avg": "$rating"}
}
})
然后当我试图提取平均值时
print('avg rating', res['avg_rating'])
这会引发错误TypeError: 'AsyncIOMotorLatentCommandCursor' object is not subscriptable
我已经用谷歌搜索了很多,但我没有找到如何使用motor
.