fix(mongodb): support legacy driver fallback

This commit is contained in:
t8y2
2026-06-15 14:07:31 +08:00
parent 090f073206
commit 7bb869d398
13 changed files with 205 additions and 72 deletions
@@ -28,7 +28,7 @@ import { isLocalFileTypeDb } from "@/lib/connectionFile";
import { mongodbAuthFailureHint, mongoUrlParam, setMongoUrlParam } from "@/lib/mongoConnectionOptions";
import { copyToClipboard } from "@/lib/clipboard";
import { showAgentDriverInstallHint, type AgentDriverInstallState } from "@/lib/agentDriverInstallHint";
import { ArrowLeft, ArrowDown, ArrowUp, CheckSquare, ChevronRight, Copy, ExternalLink, FilePlus2, FolderOpen, GripVertical, Grid3X3, KeyRound, Link2, List, ListFilter, Loader2, Pipette, Plus, Search, ShieldCheck, Square, Trash2 } from "@lucide/vue";
import { ArrowLeft, ArrowDown, ArrowUp, CheckSquare, ChevronRight, CircleHelp, Copy, ExternalLink, FilePlus2, FolderOpen, GripVertical, Grid3X3, KeyRound, Link2, List, ListFilter, Loader2, Pipette, Plus, Search, ShieldCheck, Square, Trash2 } from "@lucide/vue";
import { buildDraftVisibleDatabasesConnectionId, connectionCanChooseVisibleDatabases, initialVisibleDatabaseSelection, visibleDatabaseSelectionIsStale } from "@/lib/connectionVisibleDatabases";
import { canSaveVisibleDatabaseSelection, filterDatabaseNamesForConnection, isSystemDatabaseName, normalizeVisibleDatabaseSelection } from "@/lib/visibleDatabases";
@@ -998,6 +998,13 @@ const mongoAuthMechanism = computed({
form.value.url_params = setMongoUrlParam(form.value.url_params, "authMechanism", value === "default" ? "" : value);
},
});
const mongoDriverMode = computed({
get: () => (form.value.driver_profile === "mongodb-legacy" ? "legacy" : "auto"),
set: (value: string) => {
form.value.driver_profile = value === "legacy" ? "mongodb-legacy" : "mongodb";
form.value.driver_label = value === "legacy" ? "MongoDB (Legacy)" : "MongoDB";
},
});
function goToConnectionStep(value = selectedType.value) {
if (value !== selectedType.value) {
@@ -1029,6 +1036,9 @@ async function testConnection() {
const config = connectionConfigForSubmit(editingId.value || uuid());
const msg = await api.testConnection(config);
if (runId !== testRunId) return;
if (config.db_type === "mongodb" && /legacy driver/i.test(msg)) {
mongoDriverMode.value = "legacy";
}
testResult.value = { ok: true, message: msg };
} catch (e: any) {
if (runId !== testRunId) return;
@@ -1101,6 +1111,10 @@ function connectionConfigForSubmit(id: string): ConnectionConfig {
} else if (config.db_type === "mongodb") {
config.connection_string = normalizeMongoConnectionString(config.connection_string?.trim() || "");
}
if (config.db_type === "mongodb" && config.driver_profile !== "mongodb-legacy") {
config.driver_profile = "mongodb";
config.driver_label = "MongoDB";
}
if (config.db_type !== "oracle") {
config.sysdba = undefined;
config.oracle_connection_type = undefined;
@@ -2493,6 +2507,21 @@ function openExternalUrl(url: string) {
<!-- MongoDB: URL or form -->
<template v-else-if="form.db_type === 'mongodb'">
<div class="grid grid-cols-4 items-center gap-4">
<Label class="text-right text-xs">{{ t("connection.driverMode") }}</Label>
<div class="col-span-3 flex items-center gap-2">
<Button size="sm" :variant="mongoDriverMode === 'legacy' ? 'outline' : 'default'" @click="mongoDriverMode = 'auto'">{{ t("connection.mongoDriverAuto") }}</Button>
<Button size="sm" :variant="mongoDriverMode === 'legacy' ? 'default' : 'outline'" @click="mongoDriverMode = 'legacy'">{{ t("connection.mongoDriverLegacy") }}</Button>
<Tooltip>
<TooltipTrigger as-child>
<CircleHelp class="h-3.5 w-3.5 cursor-help text-muted-foreground hover:text-foreground" />
</TooltipTrigger>
<TooltipContent side="top" align="center" class="max-w-[320px] text-xs leading-relaxed">
{{ t("connection.mongoLegacyHint") }}
</TooltipContent>
</Tooltip>
</div>
</div>
<div class="grid grid-cols-4 items-center gap-4">
<Label class="text-right text-xs">{{ t("connection.mode") }}</Label>
<div class="col-span-3 flex gap-2">
@@ -2556,12 +2585,6 @@ function openExternalUrl(url: string) {
<Label class="text-right">{{ t("connection.urlParams") }}</Label>
<Input v-model="form.url_params" class="col-span-3" placeholder="authSource=admin&authMechanism=SCRAM-SHA-1" />
</div>
<div class="grid grid-cols-4 items-start gap-4">
<span />
<p class="col-span-3 text-xs text-muted-foreground">
{{ t("connection.mongoLegacyHint") }}
</p>
</div>
</template>
</template>
@@ -15,6 +15,7 @@ const assetIcons: Record<string, string> = {
turso: "turso.png",
redis: "redis",
mongodb: "mongodb",
mongodb_legacy: "mongodb",
clickhouse: "clickhouse",
duckdb: "duckdb",
mariadb: "mariadb",
+4 -1
View File
@@ -159,6 +159,9 @@
authDatabasePlaceholder: "Optional, often admin",
authMechanism: "Auth Mechanism",
authMechanismDefault: "Default",
driverMode: "Driver",
mongoDriverAuto: "Auto",
mongoDriverLegacy: "Legacy",
serviceName: "Service/SID",
serviceNameOnly: "Service Name",
version: "Version",
@@ -327,7 +330,7 @@
jdbcPluginHint: "Install the DBX JDBC plugin first, then import the database vendor's JDBC driver JAR.",
dmCompatHint: "Requires DM8 ODBC driver installed on your system.",
dmDownload: "Download from Dameng",
mongoLegacyHint: "MongoDB below 4.2 requires the MongoDB (Legacy) driver. If authentication fails and the user was created in admin, set Auth DB to admin.",
mongoLegacyHint: "Use Legacy for older MongoDB servers, especially versions below 4.2. If authentication fails and the user was created in admin, set Auth DB to admin.",
compatible: "Compatible",
mainstream: "Popular",
color: "Color",
+4 -1
View File
@@ -152,6 +152,9 @@
authDatabasePlaceholder: "Opcional, normalmente admin",
authMechanism: "Mecanismo de autenticación",
authMechanismDefault: "Predeterminado",
driverMode: "Controlador",
mongoDriverAuto: "Automático",
mongoDriverLegacy: "Legacy",
serviceName: "Servicio/SID",
serviceNameOnly: "Nombre de servicio",
version: "Versión",
@@ -306,7 +309,7 @@
jdbcPluginHint: "Instala primero el plugin JDBC de DBX y luego importa el JAR del driver JDBC del proveedor.",
dmCompatHint: "Requiere el driver ODBC DM8 instalado en el sistema.",
dmDownload: "Descargar desde Dameng",
mongoLegacyHint: "MongoDB inferior a 4.2 requiere el controlador MongoDB (Legacy) del Gestor de controladores; la conexión cambiará automáticamente.",
mongoLegacyHint: "Usa Legacy para servidores MongoDB antiguos, especialmente versiones anteriores a 4.2. Si falla la autenticación y el usuario se creó en admin, define Auth DB como admin.",
compatible: "Compatible",
mainstream: "Popular",
color: "Color",
+4 -1
View File
@@ -157,6 +157,9 @@
authDatabasePlaceholder: "Opzionale, spesso admin",
authMechanism: "Meccanismo di Autenticazione",
authMechanismDefault: "Predefinito",
driverMode: "Driver",
mongoDriverAuto: "Automatico",
mongoDriverLegacy: "Legacy",
serviceName: "Servizio/SID",
serviceNameOnly: "Nome Servizio",
version: "Versione",
@@ -311,7 +314,7 @@
jdbcPluginHint: "Installa prima il plugin DBX JDBC, quindi importa il file JAR del driver JDBC del fornitore del database.",
dmCompatHint: "Richiede il driver ODBC DM8 installato sul sistema.",
dmDownload: "Scarica da Dameng",
mongoLegacyHint: "MongoDB precedente a 4.2 richiede il driver MongoDB (Legacy). Se l'autenticazione fallisce e l'utente è stato creato in admin, imposta DB di Autenticazione su admin.",
mongoLegacyHint: "Usa Legacy per server MongoDB meno recenti, specialmente versioni precedenti alla 4.2. Se l'autenticazione fallisce e l'utente è stato creato in admin, imposta DB di Autenticazione su admin.",
compatible: "Compatibile",
mainstream: "Popolare",
color: "Colore",
+4 -1
View File
@@ -157,6 +157,9 @@
authDatabasePlaceholder: "Opcional, geralmente admin",
authMechanism: "Mecanismo de Autenticação",
authMechanismDefault: "Padrão",
driverMode: "Driver",
mongoDriverAuto: "Automático",
mongoDriverLegacy: "Legacy",
serviceName: "Service/SID",
serviceNameOnly: "Service Name",
version: "Versão",
@@ -311,7 +314,7 @@
jdbcPluginHint: "Instale primeiro o plugin JDBC do DBX e depois importe o JAR do driver JDBC do fornecedor do banco de dados.",
dmCompatHint: "Requer o driver ODBC DM8 instalado no seu sistema.",
dmDownload: "Baixar da Dameng",
mongoLegacyHint: "MongoDB abaixo de 4.2 requer o driver MongoDB (Legacy). Se a autenticação falhar e o usuário foi criado em admin, defina o BD de autenticação como admin.",
mongoLegacyHint: "Use Legacy para servidores MongoDB antigos, especialmente versões anteriores à 4.2. Se a autenticação falhar e o usuário foi criado em admin, defina o BD de autenticação como admin.",
compatible: "Compatível",
mainstream: "Popular",
color: "Cor",
+4 -1
View File
@@ -160,6 +160,9 @@
authDatabasePlaceholder: "可选,通常为 admin",
authMechanism: "认证机制",
authMechanismDefault: "默认",
driverMode: "驱动",
mongoDriverAuto: "自动",
mongoDriverLegacy: "旧版兼容",
serviceName: "服务名/SID",
serviceNameOnly: "服务名",
version: "版本",
@@ -328,7 +331,7 @@
jdbcPluginHint: "先安装 DBX JDBC 插件,再导入数据库厂商提供的 JDBC 驱动 JAR。",
dmCompatHint: "需要在系统上安装达梦 DM8 ODBC 驱动程序。",
dmDownload: "前往达梦官网下载",
mongoLegacyHint: "MongoDB 4.2 以下版本需安装 MongoDB (Legacy) 驱动。若账号创建在 admin 且认证失败,请将认证库设为 admin。",
mongoLegacyHint: "旧版 MongoDB(尤其是 4.2 以下版本)请选择旧版兼容。若账号创建在 admin 且认证失败,请将认证库设为 admin。",
compatible: "兼容",
mainstream: "主流",
color: "颜色",
+4 -1
View File
@@ -157,6 +157,9 @@
authDatabasePlaceholder: "可選,通常為 admin",
authMechanism: "認證機制",
authMechanismDefault: "預設",
driverMode: "驅動",
mongoDriverAuto: "自動",
mongoDriverLegacy: "舊版相容",
serviceName: "服務/SID",
serviceNameOnly: "服務名稱",
version: "版本",
@@ -311,7 +314,7 @@
jdbcPluginHint: "先安裝 DBX JDBC 外掛程式,再匯入資料庫廠商提供的 JDBC 驅動程式 JAR。",
dmCompatHint: "需要在系統上安裝達夢 DM8 ODBC 驅動程式。",
dmDownload: "前往達夢官網下載",
mongoLegacyHint: "MongoDB 4.2 以下版本需安裝 MongoDB (Legacy) 驅動程式。若帳號建立在 admin 且認證失敗,請將認證庫設為 admin。",
mongoLegacyHint: "舊版 MongoDB(尤其是 4.2 以下版本)請選擇舊版相容。若帳號建立在 admin 且認證失敗,請將認證庫設為 admin。",
compatible: "相容",
mainstream: "熱門",
color: "顏色",
@@ -8,6 +8,7 @@ export interface AgentDriverInstallState {
function agentDriverInstallKey(dbType: DatabaseType | undefined, driverProfile?: string): string | undefined {
if (dbType === "oracle") return "oracle";
if (dbType === "mongodb") return "mongodb";
return driverProfile && driverProfile !== dbType ? driverProfile : dbType;
}