Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems writing to DB after building object using a for-loop #13

Open
mongojarle opened this issue Mar 22, 2021 · 0 comments
Open

Problems writing to DB after building object using a for-loop #13

mongojarle opened this issue Mar 22, 2021 · 0 comments

Comments

@mongojarle
Copy link

As the title suggest, I'm having trouble writing to the database when using a for-loop to construct the object that I want to send. If I write out the same data one-by-one, it works like it should.
When I debug the output from my function, it is of the same format as another function where I do not use for-loop. Also the stackhero influxdb-V2 write node does give an output with empty payload (no error).
Also, if the measurement does not exist in the bucket, it will be created by the write node, so it is sending something to the DB.
This is the code used for constructing in a function node, the incoming msg.payload is an array of 24 objects. Each object consists of energy prices valid for one hour, and a timestamp to define what hour it is valid from (output from node nordpool-api-plus). This also means I will be writing to the past, and also to the future in the database.

`var dataset = [];

for (i = 0; i < msg.payload.length; i++) {
dataset.push(
{
measurement: 'technical',
tags: {
location: 'power'
},
fields: {
price: (msg.payload[i].price / 1000)
},
timestamp: Date.parse(msg.payload[i].timestamp)
}
)
}

msg.payload = {
bucket: 'test',
presicion: 'ms',
data: dataset
}
return msg;`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant