The following code will work on MongoDB 3.4. The cursor is created with the no timeout option and is left open on the server until the application closes it.
MongoDB 3.6 drivers will add an implicit session to every command. The find command will use a new session and again create a cursor with the no timeout option. However, that session will timeout after 30 minutes of inactivity and the cursor will be closed.
Users that need the cursor timeout to exceed the session timeout will need to write code to periodically refresh the session. This will prevent the session (and cursor) from timing out:
I don't think this change has been documented yet. CC Alyson Cabral
- Update noCursorTimeout to include the session refresh requirements (e.g. implicit 30 minute max)
- Update Mongo.startSession() and startSession to include the session timeout limit (30 minutes) + refreshSession
- Add the Session.refreshSession() shell method if it exists. Otherwise point to refreshSession dbcommand
- Update find/agg behavior sections to call out 30 minute session timeout behavior
- Add to Cursor.tailable, tailable pages