MongoDB中count()方法新的替换方法。
(2023-05-12 16:26:20)
标签:
mongodbcount()noattribute'count'总数 |
分类: Python |
Python中老版本的mongodb取得count都是使用count()方法,但新版中这个方法已经被废。具体可以参考
https://pymongo.readthedocs.io/en/stable/api/pymongo/collection.html#pymongo.collection.Collection.count_documents
曾经的
client = pymongo.MongoClient(host='localhost',
port=27017)
db = client.test
collection = db.students
#count = collection.find().count()
这一条被下面一条替换
count = collection.estimated_document_count()
# count = collection.find({'age': 20}).count()
这一条被下面一条替换
count = collection.count_documents({'age': 20})
前一篇:常见鱼香汁调配比例
后一篇:日语输入法常用快捷键