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

來源:互聯網
上載者:User

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

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就解決!

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.