pymong 遊標超時:pymongo.errors.CursorNotFound: Cursor not found

前言

從庫批量抽取數據或數據集較大後續代碼運行時間太長而致使遊標超時python

  • 運行env:mongodb

    python2.7
    pymongo==3.7.0
    mongodb:v3.6.6

解決方案:設置鏈接永遠不超時

client=pymongo.MongoClient(host='s3005.test.com',port=3005, connect=False)
   db = client.test
   col =db.images_new

   cursor = readm_col.find({"image_cover": 1},no_cursor_timeout=True)
   ## no_cursor_timeout設置鏈接永遠不超時

   try 
    for data in cursor:
        pass ## 一些業務邏輯
   except:
       errinfo = sys.exc_info()
       print errinfo
   finally:
       cursor.close() ## 手動關閉鏈接,釋放資源

Donepython2.7

相關文章
相關標籤/搜索