2

我想和 Motor 的潜水员一起数一数,但我收到了这个错误。

AttributeError: 'AsyncIOMotorCursor' object has no attribute 'count'

这是我的代码:

await MOTOR_CURSOR.users.find().count()
4

1 回答 1

5

MotorCollection.find()返回AsyncIOMotorCursor并且它没有count方法。相反,您应该调用MotorCollection.count_documents()

await db.users.count_documents({'x': 1})

另外值得注意的是,您所指的MOTOR_CURSORMotorDatabase实例,最好将其称为 db 实例而不是游标以避免混淆。

于 2020-03-31T06:16:44.027 回答