Getting error when upgrading mongo java driver to 4.4

I am upgrading the mongo java driver from 3.11.1 to 4.4.1.

Seems like spring data mongo also needs to be upgraded, so I am going from 2.2.0.RELEASE to 3.0.0.RELEASE. If I didn’t upgrade the spring data mongo, then it is a problem because version 2.2.0 includes mongo java driver 3.X, which hinders the overall upgrade of the mongo java driver upgrade to 4.4.1.

My spring data commons is at 2.2.0.RELEASE.

Mongo client (that worked before):

<mongo:mongo-client id=“mongoClient” host="${}" port="${mongo.port}" replica-set="${mongo.replica.set}"
<mongo:client-options connections-per-host="${}"
connect-timeout="${mongo.connection.timeout}" max-wait-time="${mongo.max.wait.time}"
socket-keep-alive=“true” socket-timeout=“1500” ssl="${mongo.ssl}" />


When I deploy the app, I am getting this error. Never got it with the old configuration.


    Caused by: com.mongodb.MongoQueryException: Query failed with error code 13 and error message 'there are no users authenticated' on server
            at com.mongodb.internal.operation.FindOperation.lambda$execute$1(
            at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$2(
            at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(
            at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$3(
            at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(
            at com.mongodb.internal.operation.OperationHelper.withSourceAndConnection(
            at com.mongodb.internal.operation.FindOperation.lambda$execute$2(
            at com.mongodb.internal.async.function.RetryingSyncSupplier.get(
            at com.mongodb.internal.operation.FindOperation.execute(
            at com.mongodb.internal.operation.FindOperation.execute(
            at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(
            at com.mongodb.client.internal.FindIterableImpl.first(


If I make the following changes, eventually I get back to the same error as above:

Spring data mongo: 3.3.0 (instead of 2.2.0.RELEASE to 3.0.0.RELEASE, trying 3.3.0)
Spring data commons: 2.2.0.RELEASE to 2.5.0
Spring framework: From 5.2.1.RELEASE to 5.3.4

I updated my local mongo server to 4.4. I’m still getting the same error.

I updated my mongo client to this. No matter what i do, it times out.

	<mongo:mongo-client id="mongoClient" host="${}" port="${mongo.port}" replica-set="rs"
		<mongo:client-settings  socket-connect-timeout="${mongo.connection.timeout}"


    Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@1ae0fa2f. Client view of cluster state is {type=REPLICA_SET, servers=[]
            at com.mongodb.internal.connection.BaseCluster.createTimeoutException(
            at com.mongodb.internal.connection.BaseCluster.selectServer(
            at com.mongodb.internal.connection.AbstractMultiServerCluster.selectServer(
            at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(
            at com.mongodb.client.internal.MongoClientDelegate.createClientSession(
            at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(
            at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(
            at com.mongodb.client.internal.FindIterableImpl.first(

Hi @Arun_Lakhotia welcome to the community!

I’m not too sure what could have caused this, but it appears that the app failed to connect to the database.

Could you check the address of the MongoDB server, verify that the database is running by connecting to it via the mongo or mongosh shell?

Also if you revert all your version changes back to what it was before, does it start working again?

Best regards

Thank you. Yes, I was able to connect to the DB by running the mongo shell.

If I reverted my changes, it worked again.

I was finally able to resolve this in this manner:

I converted the XML config to a Java app config.

From there, the error messages were more helpful. It didn’t like the connection string, it thought the part where I entered the user name and password was really the host.

I couldn’t figure out why, because the connection string looked right.

(When I was trying with the xml config, I tried both using the credential string above, as well as a connection string like this:

< connection-string=“mongodb://${mongo.username}:#{mongoCredentials.password}@${}/${mongo.dbname}?replicaSet=rs0&authSource=admin&uri.authMechanism=SCRAM-SHA-1”>

I tried many variations, hardcoding, or putting the replica set where was. Every time, I’d get that server timeout error.)

I then created the same connection string via the Java app config (instead of using the xml based config).

After getting the message via the Java app config that it couldn’t find the host (and it then printed out the user:password as the host), I then moved the credentials to the mongo client settings object, and created them via MongoCredential.createCredential().

That way, my connection string just had the replica set, database name, and ssl enabled parameter.

Then, I was able to connect when my app deployed. No more timeout error.

When I was getting the server timeouts via the xml config, it didn’t tell me what host it was trying to connect to, like when I had the java app config.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.