vicban3d
vicban3d

Reputation: 131

MongoSocketOpenException when starting MongoClient with mongo-java-driver

I'm running a java web server on Windows with a local MongoDB database using mongo-java-driver 3.2.2

When starting the server I create a new MongoClient:

MongoClient mongoClient = new MongoClient("localhost:27017", options);

(options contain some CodecRegistries)

Right after running the server I get the following log:

com.mongodb.diagnostics.logging.SLF4JLogger info

INFO: Exception in monitor thread while connecting to server localhost:27017

com.mongodb.MongoSocketOpenException: Exception opening socket

...

But then, after a few seconds, the server starts and I get the following log:

com.mongodb.diagnostics.logging.SLF4JLogger info

INFO: Opened connection [connectionId{localValue:2, serverValue:1}] to localhost:27017

com.mongodb.diagnostics.logging.SLF4JLogger info

INFO: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 0]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, roundTripTimeNanos=1691281}

I couldn't find a reason why the client would fail to connect for the first time and then recover but this behavior seems consistent with every run.

Did anyone come across similar behavior? If so, how could I solve the problem?

I'll provide any additional information if needed.

Upvotes: 3

Views: 1110

Answers (1)

dowie
dowie

Reputation: 1

turn off mongodb logger in log4f.properties like:

log4j.logger.org.mongodb = OFF

notice it is org.mongodb not com.mongodb

Upvotes: -3

Related Questions