不消耗游标 可用cursor.clone()
此时可以查看查询结果条数并且可以对游标进行遍历。
from pymongo import MongoClient
client = MongoClient('mongodb://10.225.25.19:27017')
db = client.cnpbot
table = db.docs
result = table.find({'topic': 'bot'})
print(len(list(result.clone())))
print(len(list(result.clone())))
print(len(list(result.clone())))
4
4
4
消耗游标
from pymongo import MongoClient
client = MongoClient('mongodb://10.225.25.19:27017')
db = client.cnpbot
table = db.docs
result = table.find({'topic': 'bot'})
print(len(list(result)))
print(len(list(result)))
print(len(list(result)))
4
0
0