pymongo.errors.CursorNotFound 原因+解决办法

参考链接:https://blog.csdn.net/manduner/article/details/100017047

代码参考:

client = pymongo.MongoClient('192.168.1.1', 10086)
db = client.crawler
db.authenticate("admin", "password")
table = db['table']
query = {
    "status": 1,
}
# 因处理的数据量过大,防止意外报错,建议给find函数添加参数
# no_cursor_timeout=True:永不超时,游标连接不会主动关闭
# batch_size:返回文档数,适当设置更小的参数
documents = table.find(query, no_cursor_timeout=True, batch_size=5)
i = 0
j = 0
for doc in documents:
    j += 1
    print('已跑完', j, '条数据...')

           。。。。。。(查询并处理数据)

# 查询完成后需要手动关闭数据库连接
documents.close()

 

 

你可能感兴趣的:(mongoDB,python)