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

一,超時原因

  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()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章