Reading config file to set arguments in connection string

Hello to MongoDB community.

I am newbie in using the official Mongo Scala/Java driver. I just want to know if there is a way for the MongoClient to read a configuration file where properties can be conveniently set instead of manually concatenating query params in the connection string? I have checked the documentation and tutorial from https://mongodb.github.io but I could not find something similar to what I want.

Thanks in advance.

Hi @Lloyd_Edano

We considered this a long time ago but ultimately felt it was something that should be left to a dependency injection framework like Spring (e.g. https://www.baeldung.com/spring-data-mongodb-connection) instead of implemented in the driver.

Note that every part of the connection string (and much more) can also be configured in code using ``MongoClientSettings.Builder` and related classes. See https://www.mongodb.com/docs/drivers/java/sync/current/fundamentals/connection/mongoclientsettings/ for documentation. So you can fairly easily implement something like this yourself in case you are not using a DI framework.

Regards,
Jeff

Hi @Jeffrey_Yemin

I see. Just making sure this feature is not there before I implement my own solution. Thanks a lot for confirming.