java mongocursor,MongoCursorNotFoundException

com.mongodb.MongoCursorNotFoundException: Query failed with error code

-5 and error message 'Cursor 18253096929 not found on server localhost:27017' on server localhost:27017 at

com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:90)

at

com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:49)

at

com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159)

at

com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:260)

at

com.mongodb.connection.DefaultServerConnection.getMore(DefaultServerConnection.java:225)

at

com.mongodb.operation.QueryBatchCursor.getMore(QueryBatchCursor.java:195)

at

com.mongodb.operation.QueryBatchCursor.hasNext(QueryBatchCursor.java:91)

at

com.mongodb.MongoBatchCursorAdapter.hasNext(MongoBatchCursorAdapter.java:46)

at com.downloader.DownloadHtml.saveHtml(DownloadHtml.java:75) at

com.downloader.DownloadHtml.main(DownloadHtml.java:23)

从你给的异常信息来看,这个错误并不是一开始就报的,而是在做GetMore的时候。就是说,这个游标开始的时候是正常执行的,后来失败了(验证下是不是我说的这样)。几点我能想到的可能原因:

游标闲置时间太长

参考关于游标的文档,

By default, the server will automatically close the cursor after 10 minutes of inactivity, or if client has exhausted the cursor. To override this behavior in the mongo shell, you can use the cursor.noCursorTimeout() method

虽然说的是shell,但是在Java驱动中也是同样的道理,对应的参数自己去找一下了。

自己配置的负载均衡

有些用户在mongodb前面加了keepalived或者其他类似功能的组件,导致请求被转发到了错误的结点上从而找不到之前的游标。mongodb配合驱动本身就可以做到高可用,没有必要在前面加任何负载均衡。

看看你是不是以上两种情况之一。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值