0
votes

i am starting with using Node-RED. i have no JS experience.

in 1 node for the mysql DB i have to query with msg.topic.

the return msg looks like this.

{ "topic": "SELECT sum FROM log WHERE id = 2", "payload": [ { "sum": 15 } ], "_msgid": "c93094ee.36cf68" }

How do i extract the number 15 in the example out msg.payload?

thanks.

1

1 Answers

1
votes

in function node following the query.

var sum  = msg.payload[0].sum;
...

the [] in the payload signify and array of answers so the [0] says take the first element from the array.