查询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使用完毕后,一定要关闭(游标最后都是这样,规范操作)。搞不定会出现什么诡异的错误!

mongoDB: cursor not found on server的更多相关文章

  1. com.mongodb.MongoException$CursorNotFound: cursor not found on server异常处理

    java链接MongoDB处理大量数据时经常碰到cursor not found 的异常,其实是超时所致 Exception in thread "main" com.mongod ...

  2. 【pymongo】mongodb cursor id not valid error

    参考来源: http://stackoverflow.com/questions/10298354/mongodb-cursor-id-not-valid-error http://stackover ...

  3. MongoDB整理笔记の新增Shard Server

    1.启动一个新Shard Server 进程 [root@localhost ~]# mkdir /data/shard/s2 [root@localhost ~]# /Apps/mongo/bin/ ...

  4. mongodb cursor用法

    为了营造大批量数据,我们可以这样写javascript脚本 for (var i=1;i<=10000;i++) { if(i%2==1) { db.cursortest.insert({_id ...

  5. 解决com.mongodb.MongoException$CursorNotFound: cursor 0 not found on server

    背景 经常需要执行脚本调用Java程序读取mongodb中数据,本来是转为后台进程.偶尔看看日志的简单任务.今天发现程序抛出异常“com.mongodb.MongoException$CursorNo ...

  6. Mongodb 笔记 - 性能及Java代码

    性能 以下数据都是在千兆网络下测试的结果 写入 数据量的增大会导致内存占满, 因为mongodb会将数据尽可能地载入内存, 索引占用的空间也很可观非安全模式下, 速度取决于内存是否占满能差一个数量级, ...

  7. Spark With Mongodb 实现方法及error code -5, 6, 13127解决方案

    1.spark mongo 读取 val rdd = MongoSpark.builder().sparkSession(spark).pipeline(Seq(`match`(regex(" ...

  8. MongoDB Python官方驱动 PyMongo 的简单封装

    最近,需要使用 Python 对 MongodB 做一些简单的操作,不想使用各种繁重的框架.出于可重用性的考虑,想对 MongoDB Python 官方驱动 PyMongo 做下简单封装,百度一如既往 ...

  9. MongoDB 搭建副本集

    副本集(Replica Set)是一组MongoDB实例组成的集群,由一个主(Primary)服务器和多个备份(Secondary)服务器构成.通过Replication,将数据的更新由Primary ...

随机推荐

  1. ftp服务器搭建(windows)+实现ftp图片上传对接

    ftp服务器搭建(windows): vsftpd简介: vsftpd是“very secure FTP daemon”的缩写,是一个完全免费的.开放源代码的ftp服务器软件. 下载地址: http: ...

  2. vue学习之环境配置

    最近在学习vue,就顺手记录一下... 1. 安装 nodejs https://nodejs.org   -->注:安装LTS的(LTS为长期稳定版本) 在cmd中输入 node -v 如果显 ...

  3. Java工厂模式浅析理解

    由于本人缺乏工作经验,本篇文章作为随笔,只是对工厂模式有一个简单的认识 工厂模式分为以下三种: 1:简单工厂(Simple Factory).2:工厂方法(Factory Method).3:抽象工厂 ...

  4. (转)Ubuntu安装g++-4.8

    sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install g++-4.8 ...

  5. 51nod 1094 和为k的连续区间【前缀和/区间差/map】

    1094 和为k的连续区间 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 一整数数列a1, a2, ... , an(有正有负),以及另一个整数k ...

  6. docker网络及Dockerfile

    1.制作镜像 使用阿里的yum源,网址:https://opsx.alibaba.com/mirror,或者mirrors.aliyun.com,点击帮助,就会有弹框出来. docker pull c ...

  7. Flip Game -- LeetCode

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

  8. springboot 2.0+ 自定义拦截器

    之前项目的springboot自定义拦截器使用的是继承WebMvcConfigurerAdapter重写常用方法的方式来实现的. 以下WebMvcConfigurerAdapter 比较常用的重写接口 ...

  9. MVC中的Controller中返回一个JsonResult在弹出一个下载框?

    public JsonResult ReturnTest() { return Json(new {myMsg ="hello world"}, "text/html; ...

  10. What is a mocking framework? Why is it useful?

    Today I want to talk about mocking frameworks and why they are useful. In order to do that I first n ...