IMD SolutionComputing LibraryShop main store

Troubleshooting

Why InfluxDB keeps only the last record of a Node-RED array write

Edge computing and IIoT Published 8 min read

Short answer

InfluxDB addresses a point by measurement, tag set and timestamp together, so three records that share one timestamp and carry no tags merge into a single point and the last field values win. Move the bin identifier from the fields object into the tags object and capture the cycle timestamp once; each bin then forms its own series and the shared acquisition time survives the write.

On this page
  1. Why does InfluxDB store only the last record of my array write?
  2. What makes two InfluxDB points the same point?
  3. Why does the demo flow work while my parser stores one point?
  4. How do I keep one timestamp per cycle and still store every bin?
  5. How should the array of arrays look for the influxdb out node?
  6. What does the fixed write store for the three-bin test payload?
  7. How do I verify the fix on the live database?
  8. Which other write paths drop records in InfluxDB?
  9. Questions asked

InfluxDB is not dropping your records; it is merging them. The Node-RED array is built correctly and the Debug node proves it, but every record in the batch carries the same measurement, an empty tag set and one new Date() timestamp. InfluxDB addresses a point by that triple together, so three records written in the same millisecond are three writes to one point, and the last field values win. The fix is structural: move BinID from the fields object into the tags object and capture the cycle timestamp once, so bins sampled together share one honest timestamp across three distinct series. Reformatting the JSON cannot help, because fields never take part in point identity.

Why does InfluxDB store only the last record of my array write? #

InfluxDB keeps one point per unique combination of measurement, tag set and timestamp, and your three records share the testing measurement, an empty tag set and one new Date() timestamp, so the database merges them and the last field values win.

That is documented database semantics, not a defect in the parser and not a failure of the out node: the server accepted all three points, and two of them simply addressed the point the first one created. Three things decide a point's address:

  • the measurement name, set in the out node configuration
  • the complete tag set, every key and value in it
  • the timestamp of the write

Nothing on that list reads field values. Because every bin record carries the same 13 field keys, the merged point ends with the last record's number in each key. The Debug node still shows three entries, so the loss stays invisible until you query.

What makes two InfluxDB points the same point? #

Identity is the measurement plus the complete tag set plus the timestamp; a field named BinID in the fields object never takes part, so Name0 and Name2 written as fields still address the same point at the same millisecond.

Vendor documentation calls the combination of measurement and tag set the series key. With no tags at all, every record in the batch sits in one series, and inside a series the timestamp alone picks the point. Fields are the payload of a point, never part of its address, which is why a BinID field distinguishes nothing: it changes what a point contains, not which point a write addresses. The relational habit of one row per bin, bin name as an ordinary column, does not transfer here. In a time-series schema the bin name is metadata about the source of the readings, and source identity belongs in the tag set. Once BinID is a tag, Name0 and Name2 are different series keys and can share a timestamp indefinitely without colliding.

Why does the demo flow work while my parser stores one point? #

The shipped demo hard-codes its two timestamps one second apart, 19:41:13Z and 19:41:14Z, while a parse loop that calls new Date() per record finishes in microseconds, so every record in your batch lands on the same millisecond.

The demo and your flow use the same accepted payload shape, which is what makes the comparison diagnostic: the only difference that matters is the timestamps. The demo's two stamps differ, so the database sees two identities; your three equal stamps collapse into one. The clock that new Date() reads resolves to the millisecond, and building three small objects takes microseconds, so all three calls return the same value. Raising the node's timestamp precision does not help either: three equal Date values serialize to one instant whether the write is labeled in milliseconds or nanoseconds, because precision changes the unit, not the value. Grabbing the clock once per scan, the pattern many batch parsers use, collides the same way while the bins share no tag.

How do I keep one timestamp per cycle and still store every bin? #

Move BinID out of the fields object and into the tags object, then capture new Date() once before the loop; three different BinID tag values at one timestamp are three different series, so nothing overwrites and the shared acquisition time stays honest.

That also matches the physics of the input: the PLC samples every bin in one scan, so the readings genuinely belong to a single instant, and assigning each bin a fabricated timestamp would describe a scan that never happened. Never separate simultaneous samples by a few artificial milliseconds; every later cross-check against cycle data inherits that skew. Tags separate the points without moving the time. Apply the split consistently: fields carry measured values, tags carry source identity. If more than one publisher can emit the same bin names, add another tag such as a configured line or system identifier, because two systems both writing BinID=Name0 still produce equal tag sets and still collide.

How should the array of arrays look for the influxdb out node? #

The node documentation states that an array-of-arrays payload is written as a series of points containing fields and tags, so each entry is two objects, fields first and tags second, and the out node's measurement setting stays testing.

If the payload shape itself is what you are debugging, the walkthrough on building multidimensional arrays in Node-RED for InfluxDB writes shows the structure entry by entry. For this input: split the message on ;;, split each record on ;, validate the tokens, and push one [fields, tags] pair per bin with the clock read once before the loop.

// Each record is a bin name then 13 numeric tokens, records joined by ";;".
var FIELD_KEYS = [
    "OsaTemp", "PlenumTemp", "ReturnTemp",
    "Pile1", "Pile2", "Pile3", "Pile4", "Pile5", "Pile6",
    "OsaRh", "PlenumRh", "ReturnRh", "Co2"
];
var points = [];
var cycleTime = new Date();      // one timestamp for the whole batch
var records = msg.payload.split(";;");

for (var r = 0; r < records.length; r++) {
    var tokens = records[r].split(";");
    if (tokens.length !== FIELD_KEYS.length + 1 || tokens[0].trim() === "") {
        node.error("Malformed bin record " + r, msg);
        return null;             // reject the batch, never write it partial
    }
    var fields = { time: cycleTime };
    for (var f = 0; f < FIELD_KEYS.length; f++) {
        var value = Number(tokens[f + 1]);
        if (tokens[f + 1].trim() === "" || !isFinite(value)) {
            node.error("Non-numeric value in record " + r, msg);
            return null;
        }
        fields[FIELD_KEYS[f]] = value;
    }
    points.push([fields, { BinID: tokens[0].trim() }]);  // BinID is the tag
}
msg.payload = points;
return msg;

The point time travels inside the fields object in the time property, the same place the shipped demo carries it, and the second object of each pair holds the tags. The validation rejects the whole batch when any record is malformed, so a partial write can never pass for a complete scan; route the node.error message into your diagnostics and repair the publishing format before retrying.

What does the fixed write store for the three-bin test payload? #

The test payload carries 42 tokens, three names plus 39 readings, and the fixed write stores three points at one timestamp, one per BinID tag, where the broken write stored a single point holding only the Name2 values 27 through 39.

Walk the identity arithmetic on the real payload. Each record is 1 name token plus 13 numeric tokens, so 3 records × 14 tokens = 42 tokens, all parsed. Before the fix, the three points share the measurement, an empty tag set and one timestamp: 3 writes − 2 redundant identities = 1 stored point, and the merge leaves the last record's value in every field key, from OsaTemp 27 through Co2 39. After the fix the tag sets are BinID=Name0, BinID=Name1 and BinID=Name2: 3 series × 1 timestamp = 3 points, and 3 × 13 = 39 field values land in the database with none discarded.

Write Tag set Timestamps Stored points
BinID as a field empty 1 1, holding only the Name2 values 27–39
BinID as a tag 3 values 1 3, holding all 39 readings

How do I verify the fix on the live database? #

Verify after the write, not before it: a query grouped by BinID must return three rows for the cycle timestamp, with OsaTemp reading 1, 14 and 27 for Name0, Name1 and Name2 respectively.

A direct read such as SELECT OsaTemp FROM testing WHERE BinID = 'Name0' returns 1 at the cycle timestamp, and the same read without the tag filter returns three rows for it. Then run this checklist on every flow that writes batches:

  • The Debug node ahead of the out node shows one flat array with one entry per source record.
  • Each entry's second object carries a BinID value distinct from the others.
  • The read for the cycle timestamp returns one row per bin, not one row total.
  • Spot-check fields against the source string: OsaTemp reads 1, 14 and 27, Co2 reads 13, 26 and 39.
  • After importing or copying a flow, confirm the measurement and database names in the out node still match the ones your queries use; a copy pointed at a different measurement makes healthy data look missing.

Receipt time is not acquisition time: buffering during a network outage delays whole batches, and stamping records on arrival moves them into the wrong scan. The article on fixing Node-RED InfluxDB write errors after a network outage covers the reconnection path. This payload carries no PLC timestamp, so read the clock at parse time, never at delivery, and prefer a PLC-supplied time when the format grows one.

Which other write paths drop records in InfluxDB? #

A missing record is not always an identity collision: when Telegraf flattens a JSON array and keeps one element, the cause sits in the collector, and the article on why Telegraf stores only one value of a JSON array in InfluxDB walks that variant.

Tag discipline cannot recover values the database never receives, so distinguish the two failures by where the Debug trail ends. The decision for every case in this article: records that share a measurement and tag set must not share a timestamp unless they are one and the same sample. Put source identity in the tag set, read the clock once per acquisition cycle, and verify with a query grouped by the tag after the write — never by spacing simultaneous samples apart, and never by trusting the Debug node alone.

Questions asked

Does a batch insert node avoid the overwrite?

No. Point identity lives in the database, not in the writing node. A batch insert node that takes explicit point objects, each with its own measurement, tags and fields, still merges two points that share all three. The node changes how points are shipped; only a different tag set or timestamp changes identity.

What happens to fields I omit from the second write?

The documented merge combines the new field set with the point that already exists. A field key present in both writes takes the newer value; a field key sent earlier but absent from the later write keeps its earlier value at that timestamp. Omitting a field never deletes it from that point.

Should the temperature readings themselves be tags?

No. Keep measured values in fields and reserve tags for identity you filter or group by, such as the bin name or a line identifier. Every distinct tag value creates another series in the index, so promoting 13 floating readings to tags would multiply series without adding any separation the queries need.

Why did Node-RED report no error when a record disappeared?

Because the write succeeded. Delivering three points and storing three points are different events: the server accepted all three, collapsed the duplicate identities into one point, and returned success. Verification therefore belongs after the write, with a query for the exact cycle timestamp, not only at the Debug node.

Keep reading

  • How-to

    Get the last N stored records from an Ignition tag history query

    A positive returnSize in system.tag.queryTagHistory splits the window into that many time buckets and aggregates each one, so it never yields the newest N stored events. Query raw history with no fixed return size and noInterpolation=True over a bounded window ending at a fixed cutoff, count rows, and step back through earlier windows until you reach N.

    Edge computing and IIoT

  • Troubleshooting

    Why a Node-RED timestamp creates a new InfluxDB tag

    Your timestamp is landing in the tag set, and InfluxDB line protocol gives every distinct tag value its own series, so each sample is written as a separate one-point series and the trend is blank. Put the epoch time in the point's time slot with the node's time precision set to match, and keep tags to identifiers that repeat, such as machine and sensor.

    Edge computing and IIoT

  • How-to

    Build multidimensional arrays in Node-RED for InfluxDB writes

    Cache each subscription's last value per point, re-emit it on a 100 ms inject tick, batch 10 samples per point and join them into one multidimensional array, then format line protocol in a single function node so one influxdb out node writes the whole batch. Ten points at a 100 ms tick become one 100-line write per second; the demonstrated flow neared Node-RED's limit at 80 points.

    Edge computing and IIoT