com.mongodb.MongoException$CursorNotFound: cursor not found on server異常處理


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)


解決方法非常easy:
           DBCursor cursor = collection.find(condtion);
                cursor.addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM