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

Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
This commit is contained in:
zipgandstaff authored and GitHub committed 2026-06-27 14:48:14 +08:00
1 parent 73120883b6
commit 55cd442cdb
2 files changed
+4 -2

No files matched your search

@@ -47,7 +47,8 @@ const mongoDocumentProvider: DocumentStoreProvider = {
sortInputLabel: "sort", sortInputLabel: "sort",
documentsLabel: ({ total, t }) => t("mongo.documents", { count: total }), documentsLabel: ({ total, t }) => t("mongo.documents", { count: total }),
queryPreview: ({ collection, filterJson, sortJson, skip, limit }) => { 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()})`); if (sortJson?.trim()) parts.push(`.sort(${sortJson.trim()})`);
parts.push(`.skip(${skip}).limit(${limit})`); parts.push(`.skip(${skip}).limit(${limit})`);
return parts.join(""); return parts.join("");
@@ -24,7 +24,8 @@ test("providers build store-specific query previews", () => {
const elasticsearch = documentStoreProviderFor("elasticsearch"); const elasticsearch = documentStoreProviderFor("elasticsearch");
assert.equal(mongo.documentsLabel({ total: 7, t }), "mongo.documents:7"); 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.documentsLabel({ total: 7, t }), "Documents");
assert.equal(elasticsearch.filterInputLabel, "filter"); assert.equal(elasticsearch.filterInputLabel, "filter");
assert.equal( assert.equal(