您的位置:首页 > 博客中心 > 数据库 >

mongoDB: cursor not found on server

时间:2022-03-14 02:07

查询mongoDB集合数据更新,数据有400w多。我一次用cursor(游标)取1w,处理更新。程序在某段时间运行中遍历游标时发生异常! DBCursor cursor = tabColl.find(queryObj).skip(startRow).limit(pageSize);

完整异常信息:
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)
        at com.bsdwwd.boss.util.deal.UpdateTUserMongoByInfo.deal(UpdateTUserMongoByInfo.java:106)
        at com.bsdwwd.boss.util.deal.UpdateTUserMongoByInfo.detailDeal(UpdateTUserMongoByInfo.java:53)
        at com.bsdwwd.boss.util.process.AbstractProcess.run(AbstractProcess.java:181)
        at java.lang.Thread.run(Thread.java:662)
    原因是取到的cursor对象默认是有时间限制的,时间过后cursor就没有了(我猜想应该被mongoDB后台程序回收了)   解决方法:      在获取到cursor对象后设置下      cursor.addOption(Bytes.QUERYOPTION_NOTIMEOUT);//默认游标打开有时间限制,设置成无时间限制     注意:      cursor使用完毕后,一定要关闭(游标最后都是这样,规范操作)。搞不定会出现什么诡异的错误!

热门排行

今日推荐

热门手游