Fix Mongo query bug when using <> operator

This commit is contained in:
Zaid Abdulla committed 2022-07-15 11:36:15 -07:00
1 parent 6f29267266
commit ffbcf2bbc0
2 files changed
+20 -1

No files matched your search

+2 -1
View File
@@ -77,7 +77,8 @@ export function processDeviceFilter(filter: Expression): Expression {
if (typeof e[2] === "number") { if (typeof e[2] === "number") {
const alt = (e as any[]).slice(); const alt = (e as any[]).slice();
alt[2] = new Date(e[2]); 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; return e;
} }
+18
View File
@@ -80,6 +80,24 @@ ava("filterToMongoQuery", async (t) => {
["Tags.tag1 = 123", { "Tags.tag1": 123 }], ["Tags.tag1 = 123", { "Tags.tag1": 123 }],
["Param1 = 'value1'", { "Param1._value": "value1" }], ["Param1 = 'value1'", { "Param1._value": "value1" }],
["Param1 <> 'value1'", { "Param1._value": { $nin: ["value1", null] } }], ["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 > 'value'", { "Param1._value": { $gt: "value" } }],
["Param1 IS NOT NULL", { "Param1._value": { $ne: null } }], ["Param1 IS NOT NULL", { "Param1._value": { $ne: null } }],
["Param1 LIKE 'value'", { "Param1._value": /^value$/ }], ["Param1 LIKE 'value'", { "Param1._value": /^value$/ }],