# In Change Node, setting output of mySQL node to Flow.Context gives "\[object Object\]"

**URL:** <https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580>\
**Category:** General\
**Created:** [29 April 2024 09:07 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580 "2024-04-29T09:07:53Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![IanH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ianh/32/95002_2.png) [@IanH](https://discourse.nodered.org/u/IanH)\
**Post date:** [29 April 2024 09:07 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/1 "2024-04-29T09:07:53Z")

</div>

I am trying to store the output of a node-red-node-mysql mysql node into a flow Context variable to aid verification and debuging (I keep missing output in debug pane as they only occur every 10 minutes or so).

But all it writes to the flow context is a string "[object Object]".  
 ![FlowCOntext result from SQL node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/63e53e326842608f10603a3fdd593b6543a8abdd.png)

The Change node contains:

 ![The common change Node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2ae1fbb0c0a5f564b74f28ef13d4ee658aa45cd5.png)  
(and I have also removed the msg.topic bit but same result.

I feed the same change node from a inject node where I have set payload, topic and others with the same objects I manage to capture from the mySQL node output, the flow contect variable is set correctly  
 ![FlowCOntext result from Inject](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/722eb8e50d4453275f29b8d1c83b64d6316d8197.png)

So why sending the same data, but from a different node type give different results.

Inject node (yes I even duplicated some irrelevant fields)

 ![inject node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e1a3147c9ba50e9c4b1a8d1d60e8f7a7c51ef7f.png)

Output of change Node for input from mySQL node

 ![With response from SQL node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e659193119e252db606cec67cd9149193eb64e3e.png)

and same as an object

```auto
{
  "payload": {
    "fieldCount": 0,
    "affectedRows": 0,
    "insertId": 0,
    "info": "(Rows matched: 0 Changed: 0 Warnings: 0",
    "serverStatus": 2082,
    "warningStatus": 0,
    "changedRows": 0,
    "topic": "UPDATE Parameters SET Parameter = 'House/hwTank/top/Temp' WHERE Parameter LIKE 'House_Tank';"
  },
  "parts": {
    "id": "aac8ef27eebcad89",
    "type": "array",
    "count": 41,
    "len": 1,
    "index": 13
  },
  "_msgid": "4a9ae7cba3a26ee6",
  "topic": "UPDATE Parameters SET Parameter = 'House/hwTank/top/Temp' WHERE Parameter LIKE 'House_Tank';",
  "ttl": 0,
  "_queuetimestamp": 1714320000216,
  "_queueCount": 27
}

```

Output of change Node for input from inject node

 ![With response from inject Node node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8e4a07a1903307a89ce116ca0606749e5cd0bb0d.png)

Finally a snippet of the flow

```auto
[
    {
        "id": "138151cbcdb18b2d",
        "type": "debug",
        "z": "0b6335e33844cb2a",
        "name": "debug 81",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1560,
        "y": 240,
        "wires": []
    },
    {
        "id": "ee2a903078fd0ffa",
        "type": "change",
        "z": "0b6335e33844cb2a",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "LastDBrequest",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1200,
        "y": 180,
        "wires": [
            [
                "839d56c8c874dfcd",
                "138151cbcdb18b2d"
            ]
        ]
    },
    {
        "id": "3f92fb986016d19a",
        "type": "inject",
        "z": "0b6335e33844cb2a",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "parts",
                "v": "{\"id\":\"aac8ef27eebcad89\",\"type\":\"array\",\"count\":41,\"len\":1,\"index\":13}",
                "vt": "json"
            },
            {
                "p": "ttl",
                "v": "0",
                "vt": "num"
            },
            {
                "p": "_queuetimestamp",
                "v": "1714320000216",
                "vt": "num"
            },
            {
                "p": "_queueCount",
                "v": "27",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "UPDATE Parameters SET Parameter = 'House/PresPump/Current' WHERE Parameter LIKE 'HousePresPumpCurrent';",
        "payload": "{\"fieldCount\":0,\"affectedRows\":2104477,\"insertId\":0,\"info\":\"4Rows matched: 2104477 Changed: 2104477 Warnings: 0\",\"serverStatus\":2082,\"warningStatus\":0,\"changedRows\":2104477}",
        "payloadType": "json",
        "x": 990,
        "y": 120,
        "wires": [
            [
                "ee2a903078fd0ffa"
            ]
        ]
    },
    {
        "id": "44c09ce4be5151d8",
        "type": "mysql",
        "z": "0b6335e33844cb2a",
        "mydb": "aa025dd27a4e9d87",
        "name": "",
        "x": 960,
        "y": 280,
        "wires": [
            [
                "ca1860475146d8f9",
                "80e44054eedb2ac5"
            ]
        ]
    },
    {
        "id": "ca1860475146d8f9",
        "type": "junction",
        "z": "0b6335e33844cb2a",
        "x": 1100,
        "y": 280,
        "wires": [
            [
                "307afb51c6cc7dca",
                "22397dbe0f9be484",
                "ee2a903078fd0ffa"
            ]
        ]
    },
    {
        "id": "307afb51c6cc7dca",
        "type": "debug",
        "z": "0b6335e33844cb2a",
        "name": "debug 80",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1300,
        "y": 440,
        "wires": []
    },
    {
        "id": "aa025dd27a4e9d87",
        "type": "MySQLdatabase",
        "name": "WombatHollow@ NAS",
        "host": "10.0.0.118",
        "port": "3306",
        "db": "WombatControl",
        "tz": "",
        "charset": "UTF8"
    }
]

```

Any idea as to why this anomaly

**System Config data**  
NR 3.1.0 on a  
Raspi 3B running Bullseye  
npm v9.8.1  
node v18.18.2

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 April 2024 09:24 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/2 "2024-04-29T09:24:48Z")

</div>

I have seen this behaviour before (with another node) - and I believe it has to do with the way it returns the object (not sure what the exact issue was), could you try to enable 'deep copy value' ?

edit [found my own topic](https://discourse.nodered.org/t/flow-context-object-object-while-it-exists/76339)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 April 2024 09:32 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/3 "2024-04-29T09:32:40Z")

</div>

> [@IanH](#):
>
> I keep missing output in debug pane as they only occur every 10 minutes or so

You could use [node-red-contrib-flogger](https://flows.nodered.org/node/node-red-contrib-flogger) so that you can go back and look at what happened, or just set the debug node to also output to the console, then you can look back through the node-red log to see what happened.

---

<div class="post-metadata">

**Author:** ![IanH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ianh/32/95002_2.png) [@IanH](https://discourse.nodered.org/u/IanH)\
**Post date:** [29 April 2024 09:41 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/4 "2024-04-29T09:41:08Z")

</div>

> [@Colin](#):
>
> You could use [node-red-contrib-flogger](https://flows.nodered.org/node/node-red-contrib-flogger) so that you can go back and look at what happened, or just set the debug node to also output to the console, then you can look back through the node-red log to see what happened.

Thanks Colin, but I would still like to know why this behaviour is seen

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 April 2024 09:41 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/5 "2024-04-29T09:41:47Z")

</div>

I don't see how those comments relate to my post.

---

<div class="post-metadata">

**Author:** ![IanH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ianh/32/95002_2.png) [@IanH](https://discourse.nodered.org/u/IanH)\
**Post date:** [29 April 2024 09:42 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/6 "2024-04-29T09:42:32Z")

</div>

Thanks for quick response, I have now tried 'deep Copy' and result is unchanged.

I also resorted to a function node with this short code

```auto
var DBResponse = {}
DBResponse = msg.payload
DBResponse.topic = msg.topic
flow.set("LastDBRequest1", DBResponse);
msg.payload = DBResponse
return msg;

```

The output msg is right, but the Flow Context Variable is same as for change node.

---

<div class="post-metadata">

**Author:** ![IanH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ianh/32/95002_2.png) [@IanH](https://discourse.nodered.org/u/IanH)\
**Post date:** [29 April 2024 09:43 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/7 "2024-04-29T09:43:27Z")

</div>

hit wrong reply button. corrected now

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 April 2024 09:46 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/8 "2024-04-29T09:46:19Z")

</div>

Could you try:

```auto
DBResponse = JSON.parse(JSON.stringify(msg.payload))

```

---

<div class="post-metadata">

**Author:** ![IanH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ianh/32/95002_2.png) [@IanH](https://discourse.nodered.org/u/IanH)\
**Post date:** [29 April 2024 10:36 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/9 "2024-04-29T10:36:40Z")

</div>

> [@bakman2](#):
>
> `DBResponse = JSON.parse(JSON.stringify(msg.payload))`

Thanks BakMan, that appears to work in the function node. So for the mySQL node developers, they have a bug that impacts the output of the mySQL node very subtly they might want to look at.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 April 2024 10:40 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/10 "2024-04-29T10:40:47Z")

</div>

There is an [open issue](https://github.com/node-red/node-red/issues/4098) against it.

This might also work:

```auto
DBResponse = {...msg.payload}

```

---

<div class="post-metadata">

**Author:** ![IanH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ianh/32/95002_2.png) [@IanH](https://discourse.nodered.org/u/IanH)\
**Post date:** [29 April 2024 13:23 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/11 "2024-04-29T13:23:15Z")

</div>

thanks, good to hear it is a known issue

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [29 April 2024 13:43 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/12 "2024-04-29T13:43:57Z")

</div>

ISTR that the MySQL node does not return a normal object so the debug node doesn’t handle it correctly. We don’t want to change the MySQL output as other things rely on that object type. Likewise we don’t really want to have to encumber the debug node with lots of special types as they occur. Re-parsing it to a proper object is a good work around.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 July 2024 13:44 UTC](https://discourse.nodered.org/t/in-change-node-setting-output-of-mysql-node-to-flow-context-gives-object-object/87580/13 "2024-07-28T13:44:42Z")

</div>

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