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 d
The problem is that Mongodb end the connection. You need to increase the timeout of the Mongodb Driver here is an example code.
MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
//build the connection options
builder.maxConnectionIdleTime(86400000);//set the max wait time in (ms)
MongoClientOptions opts = builder.build();
final Morphia morphia = new Morphia();
morphia.mapPackage("com.java.code");
final String hostURL = "host_url";
MongoCredential credential = MongoCredential.createCredential("username","database","Password".toCharArray());
ServerAddress address = new ServerAddress(hostURL);
List credentialList = new ArrayList<>();
credentialList.add(credential);
final MongoClient client = new MongoClient(address,credentialList,opts);
// create the Datastore connecting to the default port on the local host
datastore = morphia.createDatastore(client,"datastore");