天天看點

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont

java連結MongoDB處理大量資料時經常碰到cursor not found 的異常,其實是逾時所緻

Exception in thread "main" com.mongodb.MongoException$CursorNotFound: cursor not found on server

        at com.mongodb.DBApiLayer$Result.init(DBApiLayer.java:379)

        at com.mongodb.DBApiLayer$Result._advance(DBApiLayer.java:426)

        at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:408)

        at com.mongodb.DBCursor._hasNext(DBCursor.java:495)

        at com.mongodb.DBCursor.hasNext(DBCursor.java:515)

解決方法很簡單:

           DBCursor cursor = collection.find(condtion);

                cursor.addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);

隻要在查詢的DBCursor添加com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT就解決!