fix(mongodb): support legacy indexes and driver mode

This commit is contained in:
t8y2 committed 2026-06-23 19:47:10 +08:00
1 parent 7b03af97c8
commit 489da1b7db
5 files changed
+166 -7

No files matched your search

@@ -392,6 +392,7 @@ const driverProfiles: Record<
duckdb: { type: "duckdb", port: 0, user: "", label: "DuckDB", icon: "duckdb" },
access: { type: "access", port: 0, user: "", label: "Microsoft Access", icon: "access" },
mongodb: { type: "mongodb", port: 27017, user: "", label: "MongoDB", icon: "mongodb" },
"mongodb-legacy": { type: "mongodb", port: 27017, user: "", label: "MongoDB (Legacy)", icon: "mongodb" },
clickhouse: {
type: "clickhouse",
port: 8123,
@@ -56,6 +56,8 @@ import { completionSchemasFromTree, completionTablesFromTree } from "@/lib/compl
const PINNED_TREE_NODES_STORAGE_KEY = "dbx-pinned-tree-nodes";
const ACTIVE_CONNECTION_STORAGE_KEY = "dbx-active-connection";
const CONNECTION_HEALTH_CHECK_TTL_MS = 2000;
const MONGO_LEGACY_DRIVER_PROFILE = "mongodb-legacy";
const MONGO_LEGACY_DRIVER_LABEL = "MongoDB (Legacy)";
function sidebarObjectGroupPageSize(): number {
const settingsStore = useSettingsStore();
const size = settingsStore.desktopSettings.sidebar_table_page_size;
@@ -336,6 +338,7 @@ export const useConnectionStore = defineStore("connection", () => {
sqlserver: "SQL Server",
mongodb: "MongoDB",
oracle: "Oracle",
"mongodb-legacy": MONGO_LEGACY_DRIVER_LABEL,
elasticsearch: "Elasticsearch",
qdrant: "Qdrant",
milvus: "Milvus",
@@ -790,6 +793,26 @@ export const useConnectionStore = defineStore("connection", () => {
}
}
async function syncMongoLegacyDriverFallback(connectionId: string, previousConfig: ConnectionConfig) {
if (!isDesktop || previousConfig.db_type !== "mongodb" || previousConfig.driver_profile === MONGO_LEGACY_DRIVER_PROFILE) {
return;
}
const savedConnections = await api.loadConnections().catch(() => null);
const savedConfig = savedConnections?.map((connection) => normalizeConnection(connection)).find((connection) => connection.id === connectionId && connection.driver_profile === MONGO_LEGACY_DRIVER_PROFILE);
if (!savedConfig) return;
const idx = connections.value.findIndex((connection) => connection.id === connectionId);
if (idx < 0) return;
const nextConnections = [...connections.value];
nextConnections[idx] = {
...savedConfig,
driver_label: savedConfig.driver_label || MONGO_LEGACY_DRIVER_LABEL,
};
connections.value = nextConnections;
rebuildTreeNodes();
}
async function setDefaultDatabase(connectionId: string, database: string) {
const config = getConfig(connectionId);
if (!config || config.database === database) return;
@@ -868,6 +891,7 @@ export const useConnectionStore = defineStore("connection", () => {
try {
await beforeConnectHandler?.(config);
const id = await withConnectionAttemptTimeout(api.connectDb(config), config);
await syncMongoLegacyDriverFallback(id, config);
activeConnectionId.value = id;
connectedIds.value.add(id);
markConnectionHealthChecked(id);
@@ -984,6 +1008,7 @@ export const useConnectionStore = defineStore("connection", () => {
try {
await beforeConnectHandler?.(config);
await withConnectionAttemptTimeout(api.connectDb(config), config);
await syncMongoLegacyDriverFallback(connectionId, config);
connectedIds.value.add(connectionId);
markConnectionHealthChecked(connectionId);
activeConnectionId.value = connectionId;