欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

pymongo.errors.CursorNotFound: cursor id 1058082xxxxxxxx not found mongo索引超时

程序员文章站 2024-02-10 15:52:28
...

一,超时原因

  1. 数据量太大,mongo 的性能处理不过来
  2. 数据在处理过程中太耗时

二,解决方案

  1. 为find() 函数设置 no_cursor_timeout = True,表示游标连接不会主动关闭(需要手动关闭)
items = myset.find(no_cursor_timeout = True)
for item in items:
   print(item)
   #处理数据
items.close()
  1. 如果使用了方法一之后还出现报错,可以继续为find()函数设置batch_size参数,每次读出的的数据少一点
items = myset.find(no_cursor_timeout = True,batch_size=10)
for item in items:
  print(item)
  #处理数据
items.close()
相关标签: python基础