fix: 修复 MongoDB 筛选查询预览语法 (#1989)
Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
This commit is contained in:
parent
73120883b6
commit
55cd442cdb
|
|
@ -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("");
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue