feat(mongodb): support use command to switch database

This commit is contained in:
t8y2 committed 2026-06-22 16:42:38 +08:00
1 parent d9256fc1ec
commit 09d54d09bc
2 files changed
+50

No files matched your search

+28
View File
@@ -15,11 +15,13 @@ import {
mongoDocumentsToQueryResult,
mongoIndexesToQueryResult,
mongoWriteToQueryResult,
mongoUseToQueryResult,
parseMongoAggregateCommand,
parseMongoCountDocumentsCommand,
parseMongoFindCommand,
parseMongoGetIndexesCommand,
parseMongoWriteCommand,
parseMongoUseCommand,
type MongoAggregateSafetyOptions,
} from "@/lib/mongoShellCommand";
import { redisCommandResultToQueryResult } from "@/lib/redisQueryResult";
@@ -1538,6 +1540,32 @@ export const useQueryStore = defineStore("query", () => {
return;
}
const mongoUse = conn?.db_type === "mongodb" ? parseMongoUseCommand(sql) : null;
if (mongoUse) {
console.info("[DBX][executeTabSql:mongo-use:start]", { traceId, database: mongoUse.database });
const current = tabs.value.find((t) => t.id === id);
if (current?.executionId === executionId) {
current.database = mongoUse.database;
current.results = undefined;
current.activeResultIndex = undefined;
current.result = markQueryResultRowsRaw(mongoUseToQueryResult(mongoUse.database, performance.now() - startedAt));
touchResult(current);
current.queryAnalysis = undefined;
current.querySourceColumns = undefined;
current.queryEditabilityReason = undefined;
current.tableMeta = undefined;
current.resultBaseSql = options?.resultBaseSql ?? sql;
current.resultSortedSql = options?.resultSortedSql;
syncDisplayedResultRun(current, options?.resultBaseSql ?? sql);
}
console.info("[DBX][executeTabSql:mongo-use:done]", {
traceId,
database: mongoUse.database,
elapsed: elapsed(),
});
return;
}
console.info("[DBX][executeTabSql:execute-multi:start]", { traceId, elapsed: elapsed() });
const clientSessionId = tab.mode === "query" ? tab.id : undefined;
const executionOptions = {