sqldump

(coffee) => code

MongoDB Cursor Timeout

When using the MongoDB Java Driver, if you have long running operations that require you to keep a cursor open, you’ll end up with a MongoException that says “oops, the cursor timed out” after about 10 minutes of activity.

The Mongo docs say that cursors timeout due to inactivity, but as of driver version 2.11.1, I’ve had cursors timeout after 10 minutes even though documents were being fetched from the cursor continuously. Turns out, the fix to keep the cursor alive is surprisingly easy.

1
cursor.addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);