Loading

Python中pymongo find 遍历数据导致timeout

背景

在读取大约200W左右的数据的时候采用游标形式进行数据遍历时,超过10分钟就报错 timeout

原因

pymongo游标会在10分钟之后被关闭

解决方案

db.find({}, no_cursor_timeout=True)

官方文档说明

returned cursor is closed by the server after 10 minutes of
inactivity. If set to True, the returned cursor will never
time out on the server. Care should be taken to ensure that
cursors with no_cursor_timeout turned on are properly closed

posted @ 2021-09-08 18:05  小伟哥哥~  阅读(565)  评论(0编辑  收藏  举报