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})
曾经的
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})
