# Trying to save JSON to influxdb

**URL:** https://discourse.nodered.org/t/trying-to-save-json-to-influxdb/89814
**Category:** General
**Created:** [27 July 2024 12:32 UTC](https://discourse.nodered.org/t/trying-to-save-json-to-influxdb/89814 "2024-07-27T12:32:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![xubin](https://avatars.discourse-cdn.com/v4/letter/x/bcef8e/32.png) [@xubin](https://discourse.nodered.org/u/xubin)
#### Post date: [27 July 2024 12:32 UTC](https://discourse.nodered.org/t/trying-to-save-json-to-influxdb/89814/1 "2024-07-27T12:32:51Z")

</div>

Hey there  
I,m trying to save some data manually to my influxdb:  
(inject node)\<--\>(function node)\<--\>(influxdb out node)  
Here's my function node contents:

```auto
msg.payload = {
    "spec": 10,
    "right": 9,
    "left": 11
}
return msg;

```

The problem is that it seems that data is not added to influxdb but it is overwritten. I don't know what I'm doing wrong and whether this is a node-red related problem or influxdb related.  
Do you guys have any ideas on this matter?

---

<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: [27 July 2024 12:55 UTC](https://discourse.nodered.org/t/trying-to-save-json-to-influxdb/89814/2 "2024-07-27T12:55:51Z")

</div>

Welcome to the forum @xubin

That should certainly add a new point to the database. How do you know it is overwriting data rather than adding to it?

Please select the inject node and the influx node and Export them (CTRL+E or use the menu) and paste here.

In order to make export readable and usable it is necessary to surround it with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

### Author: ![xubin](https://avatars.discourse-cdn.com/v4/letter/x/bcef8e/32.png) [@xubin](https://discourse.nodered.org/u/xubin)
#### Post date: [28 July 2024 03:56 UTC](https://discourse.nodered.org/t/trying-to-save-json-to-influxdb/89814/3 "2024-07-28T03:56:29Z")

</div>

Thanks @Colin  
I check my DB after each inject, since the time of each record gets updated I suppose that data is overwritten.

Here's my flow:

```auto
[
    {
        "id": "d6917e29a170d08e",
        "type": "inject",
        "z": "20c088228d07a2a4",
        "name": "",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 170,
        "y": 120,
        "wires": [
            [
                "457bbc90b7b71e12"
            ]
        ]
    },
    {
        "id": "457bbc90b7b71e12",
        "type": "function",
        "z": "20c088228d07a2a4",
        "name": "function 2",
        "func": "msg.payload = [{\n \"spec\": 10,\n \"right\": 9,\n \"left\": 11\n}]\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 120,
        "wires": [
            [
                "49e76f17d94beaeb",
                "f173287b4bbdda06"
            ]
        ]
    },
    {
        "id": "49e76f17d94beaeb",
        "type": "influxdb out",
        "z": "20c088228d07a2a4",
        "influxdb": "781331b7e1a6b50a",
        "name": "",
        "measurement": "cutterc",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "smart-systems",
        "bucket": "beta-95",
        "x": 680,
        "y": 120,
        "wires": []
    },
    {
        "id": "f173287b4bbdda06",
        "type": "debug",
        "z": "20c088228d07a2a4",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 540,
        "y": 40,
        "wires": []
    },
    {
        "id": "781331b7e1a6b50a",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "database",
        "name": "",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "2.0",
        "url": "http://localhost:8086",
        "timeout": "10",
        "rejectUnauthorized": true
    }
]

```

---

<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: [28 July 2024 09:40 UTC](https://discourse.nodered.org/t/trying-to-save-json-to-influxdb/89814/4 "2024-07-28T09:40:25Z")

</div>

You have in the function

```auto
msg.payload = [{
    "spec": 10,
    "right": 9,
    "left": 11
}]
return msg;

```

If you look at the help text for the node, msg.payload should be an object, an array of two objects, or an array of arrays. Your payload is not one of those, it is an array of one object. Take the square brackets out.

> [@xubin](#):
>
> I check my DB after each inject

How are you doing that? If you still have the problem after fixing the function show us _exactly_ how you are viewing it and what you see.

---

<div class="post-metadata">

### Author: ![xubin](https://avatars.discourse-cdn.com/v4/letter/x/bcef8e/32.png) [@xubin](https://discourse.nodered.org/u/xubin)
#### Post date: [30 July 2024 09:20 UTC](https://discourse.nodered.org/t/trying-to-save-json-to-influxdb/89814/5 "2024-07-30T09:20:40Z")

</div>

Thanks @Colin  
I change my function to:

```auto
msg.payload = {
    "spec": 10,
    "right": 9,
    "left": 11
}
return msg;

```

But the problem still remains. After the first inject, this is my view in Influxdb webU:

 ![Screenshot from 2024-07-30 12-46-55](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/71a89833a1df0b712d4cf5d200e3a1fb672c7bb1.png)  
And this is after the second inject with same values:  
 ![Screenshot from 2024-07-30 12-48-13](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c90261f1916a76ec745d1b63f5c5e2cedad5ae4.png)  
This is after third inject with values: spec:20 right:30 left:40 :  
 ![Screenshot from 2024-07-30 12-49-36](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66498691b00898b12de6b478303e52fff2468241.png)  
That's weird! You can check my flow which I copied earlier. There is nothing complex in this flow but I can not figure out the problem!

---

<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: [30 July 2024 10:51 UTC](https://discourse.nodered.org/t/trying-to-save-json-to-influxdb/89814/6 "2024-07-30T10:51:57Z")

</div>

Note:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d379ec6753dfd376934ed553907b3cf6ef9cbc3.png)  
The important word is 'mean'.  
and  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/98882a7bf8abc46da67cfc946d68c1f6f6b9ad61.png)

I don't use the Data Explorer, but that suggests to me that the query is taking the average values over each hour, which explains the values shown I think.

---

<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 October 2024 10:52 UTC](https://discourse.nodered.org/t/trying-to-save-json-to-influxdb/89814/7 "2024-10-28T10:52:18Z")

</div>

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