pymongo除了遍历,怎么查到collection.find({})返回的文档条数?

res = collection.find({})

怎么知道返回的res的条数?

import pymongo
client = pymongo.MongoClient(host='localhost', port=27017)
counT = client["databaseName"]["collectionName"].count_documents(filter={})
print(f"num of documents in this collection is {counT}")

输出结果:

num of documents in this collection is 305

https://blog.csdn.net/VVVinegar/article/details/77101788?utm_source=blogkpcl0

num = collection.find({}).count