Use connection uri database if set for Mongo (#4289)

This commit is contained in:
Luck committed 2026-08-05 21:52:13 +01:00
1 parent 7fbb6869f5
commit 461fb34005
1 file changed
+8 -3
@@ -124,7 +124,12 @@ public class MongoStorage implements StorageImplementation {
.uuidRepresentation(UuidRepresentation.JAVA_LEGACY);
if (!Strings.isNullOrEmpty(this.connectionUri)) {
this.mongoClient = new MongoClient(new MongoClientURI(this.connectionUri, options));
MongoClientURI uri = new MongoClientURI(this.connectionUri, options);
this.mongoClient = new MongoClient(uri);
String databaseName = uri.getDatabase() != null ? uri.getDatabase() : this.configuration.getDatabase();
this.database = this.mongoClient.getDatabase(databaseName);
} else {
MongoCredential credential = null;
if (!Strings.isNullOrEmpty(this.configuration.getUsername())) {
@@ -148,9 +153,9 @@ public class MongoStorage implements StorageImplementation {
} else {
this.mongoClient = new MongoClient(address, credential, options.build());
}
this.database = this.mongoClient.getDatabase(this.configuration.getDatabase());
}
this.database = this.mongoClient.getDatabase(this.configuration.getDatabase());
try {
ensureIndexes();