Search code examples
mysqlsqlmqttnode-redmosquitto

Node Red Error: Cannot create property '_msgid' on string


I have this set up in Node Red: enter image description here

Using this SQL (Function) code:

msg.topic = "INSERT INTO temperature(temp, date) VALUES('" + 
msg.payload + "', 'NOW()')";

return msg.topic;

And getting this error:

function : (error)
"TypeError: Cannot create property '_msgid' on string 'INSERT INTO 
temperature(temp, date) VALUES('1.23', 'NOW()')'"

What am I doing wrong?


Solution

  • Your function is just returning a string (msg.topic), it needs to return a whole object.

    msg.topic = "INSERT INTO temperature(temp, date) VALUES('" + msg.payload + "', 'NOW()')";
    
    return msg;