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"' ] ];