pymongo.errors.CursorNotFound: cursor id 15XXX not found
报错如下:
1
| pymongo.errors.CursorNotFound: cursor id 69148817834 not found, full error: {'ok': 0.0, 'errmsg': 'cursor id 69148817834 not found', 'code': 43, 'codeName': 'CursorNotFound', 'operationTime': Timestamp(1635489732, 5), '$clusterTime': {'clusterTime': Timestamp(1635489732, 5), 'signature': {'hash': b'\x83-]Y\xc9\xc7\xfc\xfc\x8cM\xe7??\x0b&y\x84$\xe8\xc8', 'keyId': 6998485815391158278}}}
|
根据异常找到报错位置如下
1 2 3
| ret = mongo_collection.find(find_condition, projection) for i in ret: ...
|
默认 mongo server 维护连接的时间窗口是十分钟,单次从 server 获取数据是101条或者大于1M小于16M的数据
所以默认情况下,如果10分钟内未能处理完数据,则抛出该异常
解决方案:
1 2 3 4
| ret = mongo_collection.find(find_condition, projection, no_cursor_timeout = True) for i in ret: ... ret.close()
|