Mongo cursor timeout in Java

4,280 views
Skip to first unread message

dan

unread,
Sep 27, 2010, 12:21:54 PM9/27/10
to mongodb-user
http://groups.google.com/group/mongodb-user/browse_thread/thread/2572f1ec6bbf6fbe
says cursors timeout on the Mongo server after 10 minutes.

I'm seeing this. I'm using Mongo 1.6.2 and mongo-2.1.jar and I'm
getting:

com.mongodb.MongoException$CursorNotFound: cursor not found on server
at com.mongodb.DBApiLayer$Result.init(DBApiLayer.java:289)
at com.mongodb.DBApiLayer$Result._advance(DBApiLayer.java:330)

http://groups.google.com/group/mongodb-user/browse_thread/thread/e532dbefce643531/ed3fbd8e679d6673
indicates there is a NO_TIMEOUT option for the Ruby driver.

Is there a way to declare no cursor timeout using the Java driver?

The first link says the person set batch size to 100, but that seems
like a hack.

Thanks in advance.

Kristina Chodorow

unread,
Sep 27, 2010, 2:57:36 PM9/27/10
to mongod...@googlegroups.com
Use addOption with Bytes.QUERYOPTION_NOTIMEOUT (see http://api.mongodb.org/java/2.1/com/mongodb/DBCursor.html#addOption%28int%29 and http://api.mongodb.org/java/2.1/com/mongodb/Bytes.html)




--
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.


dan

unread,
Sep 27, 2010, 4:16:30 PM9/27/10
to mongodb-user
Thanks for the advice, and ref to javadocs.

Is there any way to set the timeout to be 24 hours? I realized perhaps
an unlimited timeout is unsafe.

On Sep 27, 1:57 pm, Kristina Chodorow <krist...@10gen.com> wrote:
> Use addOption with Bytes.QUERYOPTION_NOTIMEOUT (seehttp://api.mongodb.org/java/2.1/com/mongodb/DBCursor.html#addOption%2...http://api.mongodb.org/java/2.1/com/mongodb/Bytes.html)
>
> On Mon, Sep 27, 2010 at 12:21 PM, dan <dfran...@gmail.com> wrote:
>
> >http://groups.google.com/group/mongodb-user/browse_thread/thread/2572...
> > says cursors timeout on the Mongo server after 10 minutes.
>
> > I'm seeing this. I'm using Mongo 1.6.2 and mongo-2.1.jar and I'm
> > getting:
>
> > com.mongodb.MongoException$CursorNotFound: cursor not found on server
> >        at com.mongodb.DBApiLayer$Result.init(DBApiLayer.java:289)
> >        at com.mongodb.DBApiLayer$Result._advance(DBApiLayer.java:330)
>
> >http://groups.google.com/group/mongodb-user/browse_thread/thread/e532...
> > indicates there is a NO_TIMEOUT option for the Ruby driver.
>
> > Is there a way to declare no cursor timeout using the Java driver?
>
> > The first link says the person set batch size to 100, but that seems
> > like a hack.
>
> > Thanks in advance.
>
> > --
> > 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<mongodb-user%2Bunsu...@googlegroups.com>
> > .

Kristina Chodorow

unread,
Sep 27, 2010, 4:23:07 PM9/27/10
to mongod...@googlegroups.com
No, there's no way to set the timeout to a specific value.  You just have to make sure you're exhausting all of the cursor's results.


To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.

dan

unread,
Oct 4, 2010, 10:16:04 AM10/4/10
to mongodb-user
What if the code gets halfway through the results and throws an
exception or the process exits for other reasons (e.g., shutdown)?
Will the cursor ever remain open on the server?

On Sep 27, 3:23 pm, Kristina Chodorow <krist...@10gen.com> wrote:
> No, there's no way to set the timeout to a specific value.  You just have to
> make sure you're exhausting all of the cursor's results.
>
> > <mongodb-user%2Bunsu...@googlegroups.com<mongodb-user%252Buns...@googlegroups.com>

Scott Hernandez

unread,
Oct 4, 2010, 10:49:18 AM10/4/10
to mongod...@googlegroups.com
Yes, the cursor will stay open on the server till it times out, or you
get to the end.

> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages