`
String dbURI = “mongodb://host:password@ip:port/?authSource=admin&tlsCAFile=ca.crt&tlsCertificateKeyFile=client.pem&tlsCertificateKeyFilePassword=password”;
CodecRegistry pojoCodecRegistry = fromRegistries(MongoClient.getDefaultCodecRegistry(),
fromProviders(PojoCodecProvider.builder().automatic(true).build()));
MongoClientOptions.Builder builder = new MongoClientOptions.Builder()
.writeConcern(WriteConcern.UNACKNOWLEDGED)
.readPreference(ReadPreference.secondaryPreferred())
.minConnectionsPerHost(10)
.serverSelectionTimeout(2_000)
.codecRegistry(pojoCodecRegistry);
mongo = new MongoClient(new MongoClientURI(dbURI, builder));`
Getting com.mongodb.MongoSocketReadException: Prematurely reached end of stream
Exception, even though i have ca.crt and client.pem file in the path
I am able to connect to mongodb both in mongo compass and from terminal, but not from java app.
please help me with it
Chandrashekar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.