diff --git a/lib/mongodb-functions.ts b/lib/mongodb-functions.ts index fe2920f..0339dbf 100644 --- a/lib/mongodb-functions.ts +++ b/lib/mongodb-functions.ts @@ -77,7 +77,8 @@ export function processDeviceFilter(filter: Expression): Expression { if (typeof e[2] === "number") { const alt = (e as any[]).slice(); alt[2] = new Date(e[2]); - e = ["OR", e, alt]; + if (exp[0] === "<>" || exp[0] === "NOT LIKE") e = ["AND", e, alt]; + else e = ["OR", e, alt]; } return e; } diff --git a/test/mongodb-functions.ts b/test/mongodb-functions.ts index 8a59887..0983b59 100644 --- a/test/mongodb-functions.ts +++ b/test/mongodb-functions.ts @@ -80,6 +80,24 @@ ava("filterToMongoQuery", async (t) => { ["Tags.tag1 = 123", { "Tags.tag1": 123 }], ["Param1 = 'value1'", { "Param1._value": "value1" }], ["Param1 <> 'value1'", { "Param1._value": { $nin: ["value1", null] } }], + [ + "Param1 <> 1657844103524", + { + $and: [ + { "Param1._value": { $nin: [1657844103524, null] } }, + { "Param1._value": { $nin: [new Date(1657844103524), null] } }, + ], + }, + ], + [ + "Param1 = 1657844103524", + { + $or: [ + { "Param1._value": 1657844103524 }, + { "Param1._value": new Date(1657844103524) }, + ], + }, + ], ["Param1 > 'value'", { "Param1._value": { $gt: "value" } }], ["Param1 IS NOT NULL", { "Param1._value": { $ne: null } }], ["Param1 LIKE 'value'", { "Param1._value": /^value$/ }],