# Time Stamp and Influx DB problem

**URL:** <https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715>\
**Category:** General\
**Created:** [26 July 2019 11:53 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715 "2019-07-26T11:53:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![eng56](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@eng56](https://discourse.nodered.org/u/eng56)\
**Post date:** [26 July 2019 11:53 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/1 "2019-07-26T11:53:46Z")

</div>

Hello, I'm injecting in my database an array of 2 elements: the first one is the fields and the second one is the tags as sugested here : [Influx DB contrib][([https://flows.nodered.org/node/node-red-contrib-influxdb](https://flows.nodered.org/node/node-red-contrib-influxdb))]

In field I have put my timestamp because I don't want Influx DB to set the time\_stamp, I wan't to set it.

This is my debug message (msg.payload) before the input of InfluxDB node (the classic one not the Batch node):

`[{"time":1564134384,"Concentration_C02":4080,"Temperature":40.8,"Relative_Humidity":102,"Frame_Index":2},{"Device":"test_datalog","Type_Produit":"Insafe_Carbon_Sigfox","Type_Message":"Datalog"}]`

This my error message coming from InfluxDB node: Error: A 400 Bad Request error occurred: `{"error":"partial write: points beyond retention policy dropped=1"}`

This my DB retention configuration: ( I have deleted autogen retention policy)

```auto
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
un_an 8760h0m0s 168h0m0s 1 true

```

Thank you for your help

---

<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:** [26 July 2019 14:08 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/2 "2019-07-26T14:08:34Z")

</div>

Try adding three zeros to the end of the timestamp. I believe it needs to be a javascript timestamp, which is in milliseconds.

---

<div class="post-metadata">

**Author:** ![eng56](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@eng56](https://discourse.nodered.org/u/eng56)\
**Post date:** [26 July 2019 14:52 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/4 "2019-07-26T14:52:31Z")

</div>

Thank you for your answer now node-red recognize that it's a timestamp and display it as a date (without any other node as moment) but I still have the same problem :`Error: A 400 Bad Request error occurred: {"error":"partial write: points beyond retention policy dropped=1"}`

---

<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:** [26 July 2019 14:57 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/5 "2019-07-26T14:57:45Z")

</div>

Is it ok if you don't give it the timestamp, so that influx adds the timestamp? I know you don't want to do this, just checking whether it is ok otherwise.  
Also I notice that the influxdb out node does not say that you can include a timestamp. Have you tried the same thing using the batch node, which does say a timestamp can be included.

---

<div class="post-metadata">

**Author:** ![eng56](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@eng56](https://discourse.nodered.org/u/eng56)\
**Post date:** [26 July 2019 15:13 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/6 "2019-07-26T15:13:34Z")

</div>

Yes it's working very well when I don't change my timestamp but I'm receiving one payload every hour but each payload contains 3 messages (one measurement every 20 minutes).

I have just checked the InfluxDB contrib info and the time can be injected I think:

```auto
msg.payload = [
    [{
        numValue: 10,
        randomValue: Math.random()*10,
        strValue: "message1",
        time: new Date("2015-12-28T19:41:13Z").getTime()
    },
    {
        tag1:"sensor1",
        tag2:"device2"
    }],
    [{
        numValue: 20,
        randomValue: Math.random()*10,
        strValue: "message2",
        time: new Date("2015-12-28T19:41:14Z").getTime()
    },
    {
        tag1:"sensor1",
        tag2:"device2"
    }]
];
return msg;

```

---

<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:** [26 July 2019 16:33 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/7 "2019-07-26T16:33:37Z")

</div>

> [@eng56](#):
>
> I have just checked the InfluxDB contrib info and the time can be injected I think

Where have you found that example? Also the example shows an array of arrays whereas you have just shown an array in the data you showed.

---

<div class="post-metadata">

**Author:** ![eng56](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@eng56](https://discourse.nodered.org/u/eng56)\
**Post date:** [26 July 2019 20:31 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/8 "2019-07-26T20:31:36Z")

</div>

You are right it was a mistake, finally I have choosen the batch node and I'm injecting a message according to the influx node doc(the last exampke) but I still have the same error message

`Error: A 400 Bad Request error occurred: {"error":"partial write: points beyond retention policy dropped=3"}`

`[{"measurement":"real_time","fields":{"Concentration_C02":3400,"Temperature":34,"Relative_Humidity":85,"Frame_Index":2},"tags":{"Device":"test_datalog_now","Type_Produit":"Insafe_Carbon_Sigfox","Type_Message":"Datalog"},"timestamp":1564128384000},{"measurement":"real_time","fields":{"Concentration_C02":3740,"Temperature":37.4,"Relative_Humidity":93.5,"Frame_Index":2},"tags":{"Device":"test_datalog_now","Type_Produit":"Insafe_Carbon_Sigfox","Type_Message":"Datalog"},"timestamp":1564131384000},{"measurement":"real_time","fields":{"Concentration_C02":4080,"Temperature":40.8,"Relative_Humidity":102,"Frame_Index":2},"tags":{"Device":"test_datalog_now","Type_Produit":"Insafe_Carbon_Sigfox","Type_Message":"Datalog"},"timestamp":1564134384000}]`

Thank you for your support

---

<div class="post-metadata">

**Author:** ![mike](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mike/32/10_2.png) [@mike](https://discourse.nodered.org/u/mike)\
**Post date:** [26 July 2019 21:52 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/9 "2019-07-26T21:52:57Z")

</div>

From the error message, it looks like the timestamps you've provided to the Batch output node are numbers, so these will be passed in to InfluxDb for parsing. Since InfluxDb uses nanosecond precision by default, these millisecond dates may be outside of your retention policy, causing this error to be thrown.

[https://node-influx.github.io/class/src/index.js~InfluxDB.html#instance-method-writePoints](https://node-influx.github.io/class/src/index.js~InfluxDB.html#instance-method-writePoints)

Have you tried using Javascript Date objects for your timestamps as in the example? E.g. `"timestamp": new Date(1564128384000)` rather than `"timestamp":1564128384000`? This should cause the library to convert to the right precision. I think another option might be to specify the precision (e.g. 'ms') with the writes as in the `writePoints` documentation.

---

<div class="post-metadata">

**Author:** ![eng56](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@eng56](https://discourse.nodered.org/u/eng56)\
**Post date:** [27 July 2019 08:03 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/10 "2019-07-27T08:03:21Z")

</div>

If I let my time-stamp in miliseconds Node Red recongnize automatically that it's a timestamp and in the debug I can display it as a date.  
If I multiply by 1000 (to have a nanoseconds) node red don't recognize that it's a date.

Solution: To use a batchnode and using the Date object using a miliseconds precision

Thank you for your help !

---

<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 2019 08:13 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/11 "2019-07-28T08:13:41Z")

</div>

> [@eng56](#):
>
> If I multiply by 1000 (to have a nanoseconds) node red don't recognize that it's a date.

You only need to multiply it by 1000 when sending it to the influx node. Leave it as a javascript date when using it elsewhere. That would be an alternative solution.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [23 November 2019 21:42 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/12 "2019-11-23T21:42:07Z")

</div>

> [@eng56](#):
>
> If I multiply by 1000 (to have a nanoseconds)

Multiplying an epoch in milliseconds (1564128384000) by 1000 results in microseconds.  
Should be multiply by 1000000 which gives (1564128384000000000)

---

<div class="post-metadata">

**Author:** ![geralltgriffiths](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/geralltgriffiths/32/52944_2.png) [@geralltgriffiths](https://discourse.nodered.org/u/geralltgriffiths)\
**Post date:** [11 February 2022 14:17 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/13 "2022-02-11T14:17:31Z")

</div>

Somewhat late to the party, but I had pretty-much the same requirement - and the same frustration, trying to get influxdb to accept input with a time value of my choosing. (I kept getting an error message that said the time wasn't between the permitted ranges, while quoting back at me my value, which clearly was!)

Long story short:

1. use the influx batch node;
2. leave the time precision in the node as Default;
3. create a payload that's an array of objects, where every object is one row to add to the db;
4. send the time value as an integer number of nanoseconds (irrespective of whatever precision you use).

By way of example, here's the (working!) test payload I constructed:

```auto
msg.payload = [
    { // first row
        measurement: "test", 
        fields: {
            numValue: 10,
            randomValue: Math.random()*10,
            strValue: "message1",
            mytime: new Date().getTime()
        },
        tags: {
            tag1:"sensor1",
            tag2:"device2"
        },
        timestamp : new Date().getTime() * 1e6 // time now; convert milliseconds to nanoseconds
    },
    { // second row
        measurement: "test",
        fields: {
            numValue: 20,
            randomValue: Math.random()*10,
            strValue: "message2",
            mytime: new Date().getTime() + 6000000
        },
        tags: {
            tag1:"sensor1",
            tag2:"device2"
        },
        timestamp : (new Date().getTime() + 6000000 ) * 1e6 // (arbitrary) 6000s in the future
    }
];
return msg;

```

I hope that helps someone.

---

<div class="post-metadata">

**Author:** ![pagaille](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pagaille/32/18808_2.png) [@pagaille](https://discourse.nodered.org/u/pagaille)\
**Post date:** [29 March 2022 13:42 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/14 "2022-03-29T13:42:20Z")

</div>

Still, I'd like to know why it doesn't work with the Influxdb out node... That's pretty strange.

---

<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 March 2022 14:09 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/15 "2022-03-29T14:09:47Z")

</div>

> [@pagaille](#):
>
> I'd like to know why it doesn't work with the Influxdb out node

Why what doesn't work with the influx out node?

---

<div class="post-metadata">

**Author:** ![pagaille](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pagaille/32/18808_2.png) [@pagaille](https://discourse.nodered.org/u/pagaille)\
**Post date:** [29 March 2022 15:31 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/16 "2022-03-29T15:31:58Z")

</div>

I also had problems setting an arbitrary timestamp using the influx out node.

I sorted it out by setting the Time Precision setting to ms and feeding the node with an array of array containing an object with the fields and values :

```auto
[
   [{"time":1648567800000,"Power":120}],
   [{"time":1648567500000,"Power":144}]
]

```

---

<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 March 2022 15:54 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/17 "2022-03-29T15:54:04Z")

</div>

You haven't shown an example of what doesn't work.

---

<div class="post-metadata">

**Author:** ![pagaille](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pagaille/32/18808_2.png) [@pagaille](https://discourse.nodered.org/u/pagaille)\
**Post date:** [29 March 2022 18:00 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/18 "2022-03-29T18:00:47Z")

</div>

Right. I didn't set an array of array of object, only an array of object. I believe that's the same for OP, beside the time precision issue.

---

<div class="post-metadata">

**Author:** ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)\
**Post date:** [29 March 2022 18:38 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/19 "2022-03-29T18:38:52Z")

</div>

I know it adds a bit more CPU overhead, but when dealing with timestamps going to influx, I prefer to simply throw a [node-red-contrib-moment](https://flows.nodered.org/node/node-red-contrib-moment) node in the flow with the output format set to "x" (lower case is important for the formatting.) This will get your timestamp into a format that influx likes.

Here's an example payload structure I'm sending. The output of the moment node would be going to `msg.time` before the flow heads into a function that looks as follows:

```auto
msg.payload=[
    {
        [msg.payload.col7]:msg.payload.col10,
        time:msg.time,
    },
    {
        MRN:msg.payload.col1,
        bed:msg.payload.col6,
        dateOfBirth:msg.DOB,
        valUnval:"UNVALIDATED",
        deviceName:msg.payload.col6,
        flowsheetRowName:msg.payload.col7
    },
];
return msg;

```

I then send the output of this to a join node (my source data for this flow is coming from a CSV file, so it already has the split metadata) to turn it into an array of arrays.

edit: this is assuming influx 2.0.

---

<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 March 2022 19:13 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/20 "2022-03-29T19:13:04Z")

</div>

Please provide example of a payload that does not work.

**[Edit]** and tell us which influx node you want to send it to. Influxdb Out or Batch?

---

<div class="post-metadata">

**Author:** ![pagaille](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pagaille/32/18808_2.png) [@pagaille](https://discourse.nodered.org/u/pagaille)\
**Post date:** [30 March 2022 06:07 UTC](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715/21 "2022-03-30T06:07:21Z")

</div>

The OP could not write data to an InfluxDB using the Influx Out node.

There were some discussions regarding the time format, and then someone (you ?) said that writing multiple fields at a time must be done using the batch node. That's not true. You must provide an array of array of objects containing the data (fields and tags).

@JayDickson : the timestamps are not that complicated. Javascript date-related functions have a resolution to the ms. Simply configure the influx nodes ("Time Precision") to the one you use in your project.

[Next page](https://discourse.nodered.org/t/time-stamp-and-influx-db-problem/13715.md?page=2)
