feat(mongodb): add Compass-style collection import/export

This commit is contained in:
onenewcode authored and GitHub committed 2026-09-12 21:59:29 +08:00
1 parent bf4874906c
commit 8ff56b4837
47 files changed
+5626 -52

No files matched your search

@@ -16,6 +16,7 @@ const apiMock = vi.hoisted(() => ({
getColumns: vi.fn(),
getTableDdl: vi.fn(),
startTableExport: vi.fn(),
exportMongodbQuery: vi.fn(),
}));
vi.mock("@/lib/backend/api", () => apiMock);
@@ -122,6 +123,41 @@ describe("useSidebarTreeExportRuntime", () => {
expect(toastMock).toHaveBeenCalledWith("导出失败:上一个 DuckDB 查询仍在停止中,请稍后重试。", 5000);
});
it("exports a mongo collection through the save-file path without a setup dialog", async () => {
apiMock.exportMongodbQuery.mockImplementation(async (_request, onProgress) => {
onProgress({ exportId: "export-1", status: "done", documentsRead: 3, bytesWritten: 12, elapsedMs: 4 });
return { exportId: "export-1", documentsExported: 3, filePath: "orders.ndjson", elapsedMs: 4 };
});
const activeNode = shallowRef({ id: "col-1", type: "mongo-collection", label: "orders", connectionId: "conn-1", database: "shop", children: [] } as TreeNode);
const connectionStore = {
ensureConnected: vi.fn(),
getConfig: vi.fn(() => ({ db_type: "mongodb" })),
treeNodes: [],
selectedTreeNodeIds: [],
};
const runtime = useSidebarTreeExportRuntime({
activeNode,
connectionStore: connectionStore as never,
settingsStore: exportSettings() as never,
acceptedSelectionIds: () => null,
});
await runtime.exportMongoCollection("ndjson");
expect(connectionStore.ensureConnected).toHaveBeenCalledWith("conn-1");
expect(apiMock.exportMongodbQuery).toHaveBeenCalledWith(
expect.objectContaining({
connectionId: "conn-1",
database: "shop",
collection: "orders",
format: "ndjson",
filePath: "orders.ndjson",
}),
expect.any(Function),
);
expect(toastMock).toHaveBeenCalledWith("grid.exported");
});
it("loads and joins every selected DDL in tree order", async () => {
apiMock.getTableDdl.mockResolvedValueOnce("CREATE TABLE one (id INT)").mockResolvedValueOnce("CREATE VIEW two AS SELECT 1;");
const first = { id: "table-1", type: "table", label: "one", connectionId: "conn-1", database: "db", schema: "main" } as TreeNode;