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 committed 2026-06-04 16:01:31 +08:00
1 parent 594077fd84
commit 01c8072d97
2 files changed
+17 -4

No files matched your search

+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 => {