MongoException#CursorNotFound

716 views
Skip to first unread message

Ravi Dontharaju

unread,
Jan 28, 2012, 3:39:45 PM1/28/12
to mongodb-user
Hi All,

I was receiving the following exception while running a long batch job
to write/read data from an instance of MongoDB.
Exception in thread "main" com.mongodb.MongoException$CursorNotFound:
cursor not found on server
at com.mongodb.DBApiLayer$Result.init(DBApiLayer.java:391)
at com.mongodb.DBApiLayer$Result._advance(DBApiLayer.java:454)

I noticed that this was a pretty common issue and two best options to
resolve it are to
1. Set a limit to the DBCursors
2. http://api.mongodb.org/java/2.5.3/com/mongodb/Bytes.html#QUERYOPTION_NOTIMEOUT

Alright, now my problem is that I have a lot of places where I make
calls to DBCursor. I can go around updating every instance of DBCursor
but I am pretty sure it will take some iterations to get it all
right.
My question is, if there is a central configuration or way that I can
set a QUERYOPTION_NOTIMEOUT for all my DBCursors while initializing my
MongoDB bean?

Thanks,
Ravi Dontharaju

Scott Hernandez

unread,
Jan 28, 2012, 6:11:28 PM1/28/12
to mongod...@googlegroups.com

No.

You can also reduce the batchsize. 

Making the default notimeout is generally bad.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Ravi Dontharaju

unread,
Jan 30, 2012, 2:32:11 PM1/30/12
to mongodb-user
Yet another quick question. @Scott: When you say reduce batchsize, I
am assuming that you mean using limit, right?

If I need my cursor to return all the records from server, which may
be a huge number, can I give the count of all records as a parameter
to limit?

for eg:

int count = mongoConnection.getDBCollection("CPD").find().count();
DBCursor dbCursor =
mongoConnection.getDBCollection("CPD").find().limit(count);

would this be a valid replacement for Bytes.QUERYOPTION_NOTIMEOUT and
a solution to avoid Cursor time outs?

- Ravi


On Jan 28, 3:11 pm, Scott Hernandez <scotthernan...@gmail.com> wrote:
> No.
>
> You can also reduce the batchsize.
>
> Making the default notimeout is generally bad.
> On Jan 28, 2012 3:39 PM, "Ravi Dontharaju" <ravi.donthar...@gmail.com>
> wrote:
>
>
>
>
>
>
>
> > Hi All,
>
> > I was receiving the following exception while running a long batch job
> > to write/read data from an instance of MongoDB.
> > Exception in thread "main" com.mongodb.MongoException$CursorNotFound:
> > cursor not found on server
> >        at com.mongodb.DBApiLayer$Result.init(DBApiLayer.java:391)
> >        at com.mongodb.DBApiLayer$Result._advance(DBApiLayer.java:454)
>
> > I noticed that this was a pretty common issue and two best options to
> > resolve it are to
> > 1. Set a limit to the DBCursors
> > 2.
> >http://api.mongodb.org/java/2.5.3/com/mongodb/Bytes.html#QUERYOPTION_...

Eliot Horowitz

unread,
Jan 30, 2012, 2:47:58 PM1/30/12
to mongod...@googlegroups.com
limit != batchSize

batch size controls how big each batch of data being send from server
to client is.

the smaller it is, the most often it goes back, keeping the cursor open

Reply all
Reply to author
Forward
0 new messages