原因:在cursor上长时间没有进行操作,会引发cursor在mongodb服务端超时
解决办法:设置_no_cursor_timeout = True_,永不超时,游标连接不会主动关闭,需要手动关闭
pymongo
demos = db['demo'].find({}, {"_id": 0}, no_cursor_timeout=True) # 旧版本 timeout=Falsefor cursor in demos:do_something()demo.close() # 关闭游标
mongoengine
for each in article.objects(**context).timeout(False):do_something()
