Fork me on GitHub

MongoDB异常0501

pymongo.errors.CursorNotFound: Cursor not found, cursor id: 124891571478

原因

默认 mongo server维护连接的时间窗口是十分钟
默认 单次从 server获取数据是101条或者 大于1M小于16M的数据
所以默认情况下,如果10分钟内未能处理完数据,则抛出该异常。

解决办法
方法一

修改每批次获取数据量的条数,即batch size:
collection.find(condition).batch_size(5)

批量数需 估算十分钟内能处理的数据量

方法二

延长超时时间 需显示的关闭cursor

1
2
3
4
5
6
7
cursor=db.images.find({}{'id':1,'image_path':1,'_id':0},no_cursor_timeout=True)


for i in cursor:
.....
.....
cursor.close()

I'm not rich, but still hold the dream.
显示 Gitment 评论