首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

pymongo.errors.CursorNotFound: Cursor not found

先从数据库中取得所有数据 db[‘test’].find({},{_id:0}),然后对结果进行for循环 demos = db['demo'].find({},{"_id": 0}) for cursor...in demos:      do_something() 但是当do_something函数耗时过长,在cursor上长时间没有进行操作,引发cursor在mongodb服务端超时 解决方案 1、设置...no_cursor_timeout = True,永不超时,游标连接不会主动关闭,需要手动关闭 demos = db['demo'].find({},{"_id": 0},no_cursor_timeout...= True) for cursor in demos:     do_something() demo.close() # 关闭游标 2、设置batch_size返回文档数,默认应该是20个文档(...记不清了233333),可以设置小一些 #每次只返回一个文档 demos = db['demo'].find({},{"_id": 0}).batch_size(1) for cursor in demos

1.6K20
领券