# Node-red-contrib-influxdb : influxdb batch : not sure about processing an array of data

**URL:** https://discourse.nodered.org/t/node-red-contrib-influxdb-influxdb-batch-not-sure-about-processing-an-array-of-data/74267
**Category:** General
**Created:** [27 January 2023 16:45 UTC](https://discourse.nodered.org/t/node-red-contrib-influxdb-influxdb-batch-not-sure-about-processing-an-array-of-data/74267 "2023-01-27T16:45:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![stain3565](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stain3565/32/68179_2.png) [@stain3565](https://discourse.nodered.org/u/stain3565)
#### Post date: [27 January 2023 16:45 UTC](https://discourse.nodered.org/t/node-red-contrib-influxdb-influxdb-batch-not-sure-about-processing-an-array-of-data/74267/1 "2023-01-27T16:45:36Z")

</div>

I have seen some discussions regarding using the batch node for influxdb but have not got my head around it yet.

I have an array of data in msg.payload that I want to use the batch node to write an entry to a table but replacing the time value with a value in one of the array fields:

A short array of my data is below:

```auto
[{"time":"2023-01-20T00:20:03.271Z","domain":"sensor","elec_cons":7.138,"elec_cost_pounds":2.85,"elec_standing_charge_pence":49.54,"elec_tariff_pence":33.029,"entity_id":"utilities","friendly_name_str":"Utilities","gas_cons":28.756069,"gas_cost_pounds":3.23,"gas_standing_charge_pence":28.48,"gas_tariff_pence":10.244,"readings_date":20230119,"readings_date_str":"2023-01-19","value":6.08},
{"time":"2023-01-23T00:20:02.849Z","domain":"sensor","elec_cons":7.041,"elec_cost_pounds":2.82,"elec_standing_charge_pence":49.54,"elec_tariff_pence":33.029,"entity_id":"utilities","friendly_name_str":"Utilities","gas_cons":33.678944,"gas_cost_pounds":3.73,"gas_standing_charge_pence":28.48,"gas_tariff_pence":10.244,"readings_date":20230122,"readings_date_str":"2023-01-22","value":6.55},
{"time":"2023-01-24T00:20:02.673Z","domain":"sensor","elec_cons":7.419,"elec_cost_pounds":2.94,"elec_standing_charge_pence":49.54,"elec_tariff_pence":33.029,"entity_id":"utilities","friendly_name_str":"Utilities","gas_cons":21.903017,"gas_cost_pounds":2.53,"gas_standing_charge_pence":28.48,"gas_tariff_pence":10.244,"readings_date":20230123,"readings_date_str":"2023-01-23","value":5.47}
]

```

There can be a variable number of array entries.

for each of these, I would like to write a new influxdb sensor entry with the following fields:

time: this set to "readings\_date\_str" value, I guess at 00:00:00 time on that day  
elec\_cons: same as array input  
elec\_cost\_pounds: same as array input  
elec\_standing\_charge\_pence: same as array input  
elec\_tariff\_pence: same as array input  
gas\_cons: same as array input  
gas\_cost\_pounds: same as array input  
gas\_standing\_charge\_pence: same as array input  
gas\_tariff\_pence: same as array input  
total\_cost: set to "value"

I don't know how an array can be read and each processed by the batch node (although I assume this is built as a payload in a function node?) plus I am also unsure about measurement and tag fields. What do these really mean? Are the expected values in some standard list of values?

There are mentions of iterating through arrays in discussions but not many good examples of how that is actually coded.

---

<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 January 2023 09:38 UTC](https://discourse.nodered.org/t/node-red-contrib-influxdb-influxdb-batch-not-sure-about-processing-an-array-of-data/74267/2 "2023-01-28T09:38:58Z")

</div>

> [@stain3565](#):
>
> I am also unsure about measurement and tag fields

That is not really a node-red issue, it is an influxdb issue, but basically anything that is a process measurement should be a field, and anything that is a identifier of some sort, such as meter id, batch number, operator name and so on should be a tag. Tags are automatically indexed so that you can efficiently search by, for example, meter\_id in a query. Possible, therefore, domain, entity\_id and friendly\_name\_str should be tags, if you need to record them that is.

As to formatting the data for the batch node, is all the data in the array to go in the same influxdb measurement? If so then it may be easier to use the normal influxdb out node, which can be given a set of data in an array as described in the help text. If you look at the [node's page on the node-red flows site](https://flows.nodered.org/node/node-red-contrib-influxdb) the last example in the section on the influxdb out node shows exactly that.

---

<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: [29 March 2023 09:39 UTC](https://discourse.nodered.org/t/node-red-contrib-influxdb-influxdb-batch-not-sure-about-processing-an-array-of-data/74267/3 "2023-03-29T09:39:08Z")

</div>

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