fix: support MongoDB Atlas SRV connections in form mode

Add an "SRV (MongoDB Atlas)" toggle in the MongoDB connection form.
When enabled, the backend uses mongodb+srv:// scheme and omits the
port, matching the behavior of pasting a mongodb+srv:// URL directly.
This commit is contained in:
t8y2
2026-06-04 16:01:31 +08:00
parent 594077fd84
commit 01c8072d97
2 changed files with 17 additions and 4 deletions
@@ -2145,7 +2145,14 @@ function openExternalUrl(url: string) {
<div class="grid grid-cols-4 items-center gap-4">
<Label class="text-right">{{ t("connection.host") }}</Label>
<Input v-model="form.host" class="col-span-2" />
<Input v-model.number="form.port" type="number" class="col-span-1" />
<Input v-model.number="form.port" type="number" class="col-span-1" :disabled="form.ssl" />
</div>
<div class="grid grid-cols-4 items-center gap-4">
<span />
<label class="col-span-3 flex items-center gap-2 text-sm">
<input type="checkbox" v-model="form.ssl" class="mr-0" />
<span>SRV (MongoDB Atlas)</span>
</label>
</div>
<div class="grid grid-cols-4 items-center gap-4">
<Label class="text-right">{{ t("connection.user") }}</Label>
+9 -3
View File
@@ -405,7 +405,10 @@ impl ConnectionConfig {
suffix.push_str("&directConnection=true");
}
}
format!("mongodb://{host}:{port}{db_part}{suffix}")
let scheme = if self.ssl { "mongodb+srv" } else { "mongodb" };
// SRV URLs resolve the port via DNS SRV records, so we omit the explicit port.
let addr = if self.ssl { host.to_string() } else { format!("{host}:{port}") };
format!("{scheme}://{addr}{db_part}{suffix}")
}
DatabaseType::Oracle => format!("oracle://{host}:{port}{db_part}"),
DatabaseType::Elasticsearch => {
@@ -508,10 +511,13 @@ impl ConnectionConfig {
suffix.push_str("&directConnection=true");
}
}
let scheme = if self.ssl { "mongodb+srv" } else { "mongodb" };
// SRV URLs resolve the port via DNS SRV records, so we omit the explicit port.
let addr = if self.ssl { host.to_string() } else { format!("{host}:{port}") };
if self.username.is_empty() {
format!("mongodb://{host}:{port}{db_part}{suffix}")
format!("{scheme}://{addr}{db_part}{suffix}")
} else {
format!("mongodb://{username}:{password}@{host}:{port}{db_part}{suffix}")
format!("{scheme}://{username}:{password}@{addr}{db_part}{suffix}")
}
}
DatabaseType::Oracle => {