Ticket: Handling Timeouts (MongoDBConfiguration)

I was able to realize the ticket, however I configured the timeout via uri, below how the MongoDBConfiguration class is configured and working with the timeout set in uri

ConnectionString connString = new ConnectionString(connectionString);

MongoClientSettings settings = MongoClientSettings.builder()
          .writeConcern(WriteConcern.MAJORITY)
          .applyConnectionString(connString).build();

MongoClient mongoClient = MongoClients.create(settings);

return mongoClient;

Now as I tried setting the timeout via MongoClientSettings, but it did not work:

ConnectionString connString = new ConnectionString(connectionString);

MongoClientSettings settings = MongoClientSettings.builder()
        .writeConcern(WriteConcern.MAJORITY)
        .applyToSocketSettings(builder -> builder.connectTimeout(2500, TimeUnit.MILLISECONDS))
        .applyConnectionString(connString).build();

MongoClient mongoClient = MongoClients.create(settings);

return mongoClient;

I would like to configure the MongoDBConfiguration class to make the timeout work through the class

Hi @flp_correa,

There may be a couple of things that are causing this error.

  1. The connection string doesn’t have the needed appendage.
    and
  2. the WriteConcern in your initial solution should contain this 2500, TimeUnit.MILLISECONDS information rather than within a different setting.

Since your connection string is fine, you should be looking at your WriteConcern settings to resolve this issue.

Hope this helps.

Let me know if you are still running into this issue.

-Yulia

1 Like

Hi, @yulia_genkina
Passing the information through the uri is working.