Skip to content

Commit

Permalink
Set application name in MongDB driver config
Browse files Browse the repository at this point in the history
With this change, it's possible to see connections coming from Liquibase
in the MongoDB log files.
  • Loading branch information
Max Marcon authored and KushnirykOleh committed Aug 27, 2024
1 parent 056215d commit f904171
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.mongodb.ConnectionString;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoClientSettings.Builder;
import liquibase.Scope;
import liquibase.exception.DatabaseException;
import liquibase.util.StringUtil;
Expand All @@ -23,8 +25,14 @@ public Connection connect(final String url, final Properties info) {

public MongoClient connect(final ConnectionString connectionString) throws DatabaseException {
final MongoClient client;

MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.applicationName("Liquibase")
.build();

try {
client = MongoClients.create(connectionString);
client = MongoClients.create(settings);
} catch (final Exception e) {
throw new DatabaseException("Connection could not be established to: "
+ connectionString.getConnectionString(), e);
Expand Down

0 comments on commit f904171

Please sign in to comment.