Background
It is often necessary to execute scripts to call Java programs to read the data in MongoDB, which would have been a simple task of switching to a background process and occasionally looking at logs. Today the Discovery program throws an exception "Com.mongodb.mongoexception$cursornotfound:cursor 0 not found on server". I didn't care at first, re-execution can continue to run, but after a while to throw the same mistake, it seems to fight.
Analysis
On Mogondb.org's official website, I found the same problem, a problem that was discovered and solved in 2013 years, and the official responded to the bug, and it was resolved in the version (2.11.0 release). The exception is because the cursor timed out .
exception: Perhaps in the operation involving Oplog, or there will be problems, please refer to: https://jira.mongodb.org/browse/JAVA-771
Solve
Scenario 1: Update the MongoDB class library to 2.11.0 above.
Scenario 2: If we cannot update the MOGONDB class library, it can also be resolved by setting the timeout parameter, as follows:
Cursor.addoption (Com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);
Reference
Cursor not found on server:https://jira.mongodb.org/browse/java-907
Repeated cursornotfound exceptions on long-running process following oplog:https://jira.mongodb.org/browse/java-771
Fix com.mongodb.mongoexception$cursornotfound:cursor 0 not found on server