Ali*_*aji 5 python mongodb pymongo motorengine
我想与 Motor 的潜水员进行计数,但出现此错误。
AttributeError: 'AsyncIOMotorCursor' object has no attribute 'count'
这是我的代码:
await MOTOR_CURSOR.users.find().count()
Run Code Online (Sandbox Code Playgroud)
MotorCollection.find()返回AsyncIOMotorCursor并且它没有count方法。相反,您应该调用MotorCollection.count_documents()。
await db.users.count_documents({'x': 1})
Run Code Online (Sandbox Code Playgroud)
另外值得注意的是,您所指的是MOTOR_CURSORMotorDatabase实例,最好将其称为数据库实例而不是游标以避免混淆。