Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix: 修复 MongoDB 筛选查询预览语法 (#1989)

zipg55cd442cdb42
diff --git a/apps/desktop/src/lib/documentStoreProvider.ts b/apps/desktop/src/lib/documentStoreProvider.ts
index 68c773290a..4e879f994b 100644
--- a/apps/desktop/src/lib/documentStoreProvider.ts
+++ b/apps/desktop/src/lib/documentStoreProvider.ts
@@ -47,7 +47,8 @@ const mongoDocumentProvider: DocumentStoreProvider = {
sortInputLabel: "sort",
documentsLabel: ({ total, t }) => t("mongo.documents", { count: total }),
queryPreview: ({ collection, filterJson, sortJson, skip, limit }) => {
- const parts = [`db.${collection}.find(${filterJson || "{}"})`];
+ const collectionRef = `db.getCollection(${JSON.stringify(collection)})`;
+ const parts = [`${collectionRef}.find(${filterJson || "{}"})`];
if (sortJson?.trim()) parts.push(`.sort(${sortJson.trim()})`);
parts.push(`.skip(${skip}).limit(${limit})`);
return parts.join("");
diff --git a/packages/app-tests/documentStoreProvider.test.ts b/packages/app-tests/documentStoreProvider.test.ts
index 4e93e8d745..a5da898c32 100644
--- a/packages/app-tests/documentStoreProvider.test.ts
+++ b/packages/app-tests/documentStoreProvider.test.ts
@@ -24,7 +24,8 @@ test("providers build store-specific query previews", () => {
const elasticsearch = documentStoreProviderFor("elasticsearch");
assert.equal(mongo.documentsLabel({ total: 7, t }), "mongo.documents:7");
- assert.equal(mongo.queryPreview({ collection: "orders", filterJson: '{"city":"长治"}', sortJson: '{"createdAt":-1}', skip: 20, limit: 10 }), 'db.orders.find({"city":"长治"}).sort({"createdAt":-1}).skip(20).limit(10)');
+ assert.equal(mongo.queryPreview({ collection: "orders", filterJson: '{"city":"长治"}', sortJson: '{"createdAt":-1}', skip: 20, limit: 10 }), 'db.getCollection("orders").find({"city":"长治"}).sort({"createdAt":-1}).skip(20).limit(10)');
+ assert.equal(mongo.queryPreview({ collection: "order-events", filterJson: '{"city":"长治"}', sortJson: undefined, skip: 0, limit: 100 }), 'db.getCollection("order-events").find({"city":"长治"}).skip(0).limit(100)');
assert.equal(elasticsearch.documentsLabel({ total: 7, t }), "Documents");
assert.equal(elasticsearch.filterInputLabel, "filter");
assert.equal(