From ab27ebfaefd3565a40144c0baf41de2a11bdb888 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Tue, 29 Oct 2019 13:01:47 -0700 Subject: [PATCH] Fix bug in mongoQueryToFilter --- lib/mongodb-functions.ts | 9 ++++++--- test/mongodb-functions.ts | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/mongodb-functions.ts b/lib/mongodb-functions.ts index fc0d060..e3aaec0 100644 --- a/lib/mongodb-functions.ts +++ b/lib/mongodb-functions.ts @@ -522,9 +522,12 @@ export function mongoQueryToFilter(query): Expression { } exps.push([op, ["PARAM", k], vv]); } - if (exps.length === 1) return exps[0]; - const and: Expression = ["AND"]; - expressions.push(and.concat(exps)); + if (exps.length === 1) { + expressions.push(exps[0]); + } else { + const and: Expression = ["AND"]; + expressions.push(and.concat(exps)); + } } else { expressions.push(["=", ["PARAM", k], v]); } diff --git a/test/mongodb-functions.ts b/test/mongodb-functions.ts index 5e35ec0..342372e 100644 --- a/test/mongodb-functions.ts +++ b/test/mongodb-functions.ts @@ -32,6 +32,10 @@ ava("mongoQueryToFilter", t => { [ { test: { $gte: "test1", $ne: "test2" } }, 'test >= "test1" AND test <> "test2"' + ], + [ + { test: "test", test2: { $ne: "test2" } }, + 'test = "test" AND test2 <> "test2"' ] ];