[pymongo] pymongo.errors.CursorNotFound Exception

由於find之後,loop執行時間過長導致timeout, cusor失效

解決方式有以下幾種:

1. 使用batch_size()

    cursor = collection.find({}).batch_size(30)

2. 將取出的cursor轉為list

    result = list(collection.find({}))

3. 取消timeout限制,要在cursor使用之後close

    cursor = collection.find({}, no_cursor_timeout=True)

    cursor.close() 

# 最後一種方式,在使用時依然出現exception, 不清楚原因,有知道的朋友也請不吝賜教。

原文地址:https://www.cnblogs.com/sipher/p/11406898.html