【发布时间】:2022-12-16 11:44:28
【问题描述】:
我正在尝试获取保存在 MongoDB 中的对象数量
db = myclient.database_sample
my_collection = db["database"]
mydoc = my_collection.find().count()
print("The number of documents in collection : ", mydoc)
但我收到一个错误
mydoc = my_collection.find().count()
AttributeError: 'Cursor' object has no attribute 'count'
我正在使用 Pymongo 2.0
【问题讨论】: