I have a mysql node that the return is dynamic.
It can go back 10 lines or no lines at all.
I want to test the amount of rows returned in an IF node to handle and forward to a message for when there are no results and another message for when there are results.
I tried an expression in the if
{{$node[“MySQL”].json[“data”].length === 0}}
I also tried a code
if (Object.keys(items[0].json).length === 0) {
return [null, items[0]];
}
return [items[0], null];
I guess you have enabled the option “Always Output Data” in the MySQL node. (With that the node always outputs something even if there is no output from the MySQL query)
Here is a small demo how you could solve that with a simple expression in the IF node: {{Object.keys($items()[0].json).length === 0}}