2024-09-29 06:26:43 发布
网友
我想和摩托的潜水员一起数数,但我出错了
AttributeError: 'AsyncIOMotorCursor' object has no attribute 'count'
这是我的代码:
await MOTOR_CURSOR.users.find().count()
MotorCollection.find()返回AsyncIOMotorCursor,但它没有count方法。相反,您应该调用MotorCollection.count_documents()
count
await db.users.count_documents({'x': 1})
还值得注意的是,您所指的MOTOR_CURSOR是MotorDatabase实例,最好将其称为db实例而不是游标,以避免混淆
MOTOR_CURSOR
MotorCollection.find()返回AsyncIOMotorCursor,但它没有
count
方法。相反,您应该调用MotorCollection.count_documents()还值得注意的是,您所指的
MOTOR_CURSOR
是MotorDatabase实例,最好将其称为db实例而不是游标,以避免混淆相关问题 更多 >
编程相关推荐