I get this error on a find
call (default Java Driver) after a period of inactivity. I tried to add a manual heartbeat (writing to a capped collection), but it didn't help. I only get the issue while being connected to an instance on compose (i.e. not in a local context).
MongoDB version is 3.2.8, latest driver (3.3), using Java 8.
Any idea ?
I agree with Rhangaun's answer here is my soluction in code of JAVA:
Here is my research link:http://3t.io/blog/how-to-prevent-your-connection-from-dropping-with-hosted-mongodb-instances/
Hope it helps you.
I found it in some documentation:
For long running applications, it is often prudent to enable "keepAlive" with a number of milliseconds. Without it, after some period of time you may start to see "connection closed" errors for what seems like no reason.
Check if this helps. When you connect to mongoDB you can pass socket options to it. I am from node background we use following options to keep it alive.
Hope this helps!!
This worked for me in spring boot and cloud based mongo (Atlas clustered instances).
Edit application.properties like this:
For regular mongo instances (non-clustered) use this:
I solve this problem by set sslEnabled to true,code sample:
Addition: my client jar is org.mongodb.mongodb-driver 3.6.4,server is mongodb atlas M0 3.6.6 on GCP