MySQL No Data Return (Or no)

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

Any idea?

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}}



this work to me.

But in the mysql node, check Always Output Data.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.