From 01c8072d97e328f4ac10582452c33560fecb06dc Mon Sep 17 00:00:00 2001
From: t8y2 <1156263951@qq.com>
Date: Thu, 4 Jun 2026 16:01:31 +0800
Subject: [PATCH] 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.
---
.../src/components/connection/ConnectionDialog.vue | 9 ++++++++-
crates/dbx-core/src/models/connection.rs | 12 +++++++++---
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue
index 12a1e1ac6e..50ecbe6f50 100644
--- a/apps/desktop/src/components/connection/ConnectionDialog.vue
+++ b/apps/desktop/src/components/connection/ConnectionDialog.vue
@@ -2145,7 +2145,14 @@ function openExternalUrl(url: string) {
-
+
+
+
+
+
diff --git a/crates/dbx-core/src/models/connection.rs b/crates/dbx-core/src/models/connection.rs
index cfbe621eb8..41257732de 100644
--- a/crates/dbx-core/src/models/connection.rs
+++ b/crates/dbx-core/src/models/connection.rs
@@ -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 => {