MongoSocketReadException

Hi

As part of M220J course I am trying to bring up application using command “mvn spring-boot:run”, but I am getting error “com.mongodb.MongoSocketReadException: Prematurely reached end of stream”.

please help me in resolving this issue.

configuration:
spring.mongodb.uri=mongodb://<UserName>:<Password>@mflix-shard-00-00-vdh62.mongodb.net:27017,mflix-shard-00-01-vdh62.mongodb.net:27017,mflix-shard-00-02-vdh62.mongodb.net:27017/mflix

StackTrace:
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
at com.mongodb.internal.connection.SocketChannelStream.read(SocketChannelStream.java:116) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:570) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:441) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:295) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:106) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:63) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:127) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-3.9.1.jar:na]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_202]

Thanks,
Arjun

Hi @Arjun_40313,

Are you forgetting something ?
Also, this URI is not in the SRV format. This will work, but we recommend you using the SRV MongoDB URI connection string.

N.

Not sure what was the issue earlier SRV format was not working (got unable to resolve host name), that is why I used individual servers in uri.

now SRV format is working and I am able to start the application.

Thanks for your inputs.

1 Like