InfluxDB keed time formating

Hello.
I use node-red-contrib-influxdb.
After query it returns time as "2021-08-21T16:50:28.552Z" (if I set RAW it has microseconds).

{"_msgid":"2535bbc93736d80a","payload":[
{"time":"2021-08-21T16:50:28.552Z","BME280_Pressure":909.68,"BME280_Temperature":-146.93,"hostname":"weather"},
{"time":"2021-08-21T16:51:28.522Z","BME280_Pressure":909.68,"BME280_Temperature":-146.93,"hostname":"weather"},
{"time":"2021-08-21T16:53:28.544Z","BME280_Pressure":909.68,"BME280_Temperature":-146.93,"hostname":"weather"},
{"time":"2021-08-21T18:45:23.572Z","BME280_Pressure":909.68,"BME280_Temperature":-146.93,"hostname":"weather"},
{"time":"2021-08-22T08:10:35.013Z","BME280_Pressure":909.68,"BME280_Temperature":-146.93,"hostname":"weather"}],"topic":""}

If i do the same in console:

time                BME280_Pressure BME280_Temperature hostname
----                --------------- ------------------ --------
1629564628552540290 909.68          -146.93            weather
1629564688522635965 909.68          -146.93            weather
1629564808544065157 909.68          -146.93            weather
1629571523572056292 909.68          -146.93            weather
1629619835013378116 909.68          -146.93            weather

After it I use 2 func:

func1()
return [msg.payload];

func2()

msg.query="delete from database WHERE time='"+msg.time"'";
return msg;

I have trouble with deleting it from influx. I need use time in microseconds (1629564628552540290), but node-red-contrib-influxdb converts it with js.

  1. How can I disable converting time and keep it as influx API returns?
    or
  2. How can I convert it back to microseconds? (valueof() returns miliseconds only).
    or
  3. I fond convertTimeToNanos() function in influxdb-client-js but i can't find out how can I use this function?

My flow:

[
    {
        "id": "416a6bb38ccb8a89",
        "type": "influxdb in",
        "z": "50e7cc8e7bad66aa",
        "influxdb": "5c85923c32f22a0f",
        "name": "SensorErrors",
        "query": "select BME280_Pressure,BME280_Temperature,hostname from mqttc where time > now() - 1d and BME280_Temperature < -100 OR BME280_Pressure > 800 OR BME280_Pressure < 660",
        "rawOutput": false,
        "precision": "",
        "retentionPolicy": "",
        "org": "organisation",
        "x": 250,
        "y": 300,
        "wires": [
            [
                "36db782fed6f8bc5",
                "1593075f4457d115"
            ]
        ],
        "icon": "font-awesome/fa-info-circle"
    },
    {
        "id": "287f160d085e6db1",
        "type": "inject",
        "z": "50e7cc8e7bad66aa",
        "name": "Run",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 90,
        "y": 300,
        "wires": [
            [
                "416a6bb38ccb8a89"
            ]
        ]
    },
    {
        "id": "2e52885e4a0345ab",
        "type": "influxdb in",
        "z": "50e7cc8e7bad66aa",
        "influxdb": "5c85923c32f22a0f",
        "name": "DeleteWrong",
        "query": "",
        "rawOutput": false,
        "precision": "",
        "retentionPolicy": "",
        "org": "organisation",
        "x": 870,
        "y": 300,
        "wires": [
            []
        ],
        "icon": "font-awesome/fa-remove"
    },
    {
        "id": "41cab9442b0a932c",
        "type": "function",
        "z": "50e7cc8e7bad66aa",
        "name": "",
        "func": "msg.query=\"delete from mqttc WHERE time='\"+msg.time\"'\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 580,
        "y": 300,
        "wires": [
            [
                "36db782fed6f8bc5",
                "2e52885e4a0345ab"
            ]
        ]
    },
    {
        "id": "36db782fed6f8bc5",
        "type": "debug",
        "z": "50e7cc8e7bad66aa",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 380,
        "wires": []
    },
    {
        "id": "1593075f4457d115",
        "type": "function",
        "z": "50e7cc8e7bad66aa",
        "name": "",
        "func": "return [msg.payload];",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 300,
        "wires": [
            [
                "41cab9442b0a932c"
            ]
        ]
    },
    {
        "id": "5c85923c32f22a0f",
        "type": "influxdb",
        "hostname": "172.16.95.15",
        "port": "8086",
        "protocol": "http",
        "database": "arduino",
        "name": "influxdb",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "1.x",
        "url": "http://172.16.95.15:8086",
        "rejectUnauthorized": true
    }
]

It is probably more efficient to use a split node for that.

What have you specified for the timestamp resolution in the advanced settings of the influx node?

Are you sure it is returning a string for the timestamp? What do you see if you add this to the start of the second function
node.warn(typeof msg.time)

I was able to do it but other way.

I meet a couple of troubles:

  1. node-red-contrib-influxdb generate wrong request. If I select nanosec then module set "epoch=" instead of "epoch=ns". innflux returns text date (not integer value). I replace it regular "http request".

  2. JS can't work with long int. And I have to use bigInt to parse my json and process it.

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