一,超时原因
- 数据量太大,mongo 的性能处理不过来
- 数据在处理过程中太耗时
二,解决方案
- 为find() 函数设置 no_cursor_timeout = True,表示游标连接不会主动关闭(需要手动关闭)
items = myset.find(no_cursor_timeout = True)
for item in items:
print(item)
#处理数据
items.close()
- 如果使用了方法一之后还出现报错,可以继续为find()函数设置batch_size参数,每次读出的的数据少一点
items = myset.find(no_cursor_timeout = True,batch_size=10)
for item in items:
print(item)
#处理数据
items.close()