我想和 Motor 的潜水员一起数一数,但我收到了这个错误。
AttributeError: 'AsyncIOMotorCursor' object has no attribute 'count'
这是我的代码:
await MOTOR_CURSOR.users.find().count()
我想和 Motor 的潜水员一起数一数,但我收到了这个错误。
AttributeError: 'AsyncIOMotorCursor' object has no attribute 'count'
这是我的代码:
await MOTOR_CURSOR.users.find().count()
MotorCollection.find()返回AsyncIOMotorCursor并且它没有count
方法。相反,您应该调用MotorCollection.count_documents()。
await db.users.count_documents({'x': 1})
另外值得注意的是,您所指的MOTOR_CURSOR
是MotorDatabase实例,最好将其称为 db 实例而不是游标以避免混淆。