Skip to content

How to query multiple fields from influxdb-v2 using stackhero query node #19

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

Open
robertotarga opened this issue Nov 11, 2022 · 1 comment

Comments

@robertotarga
Copy link

robertotarga commented Nov 11, 2022

Hi,
thank you for having developed such a nice node!
I'm using the stackhero-influxdbv2 node version 1.0.4 with Node-red v. 3.0.2. with influxdb v.2.5 on a windows 11 pro pc.

Following your code example it's been very easy to write a measurement with multiple fields, but I struggle in querying more than one field in order to plot them in a table or a multiline graph for example.

Using this code I get "records" correctly:

msg.topic = [
'from(bucket: "domotica") |> range(start: -3d)',
' |> filter(fn: (r) => r._measurement == "energy")',
' |> filter(fn: (r) => r._field == "consumption")'
].join('\n');;
return msg;

but adding another r.field such as r._field == "production"):

msg.topic = [
'from(bucket: "domotica") |> range(start: -3d)',
' |> filter(fn: (r) => r._measurement == "energy")',
' |> filter(fn: (r) => r._field == "consumption")',
' |> filter(fn: (r) => r._field == "production")'
].join('\n');;
return msg;

returns an empty object!

Can you please provide the correct syntax to be able to query more than one field in the same response msg from influxdb?

@robertotarga
Copy link
Author

Since I got no reply I investigated the flux syntax and find out the solution with more than one field and to assemble the output of multiple fields in one row using pivot() function as in the example:

msg.topic = [
'from(bucket: "domotica") |> range(start: -3d)',
' |> filter(fn: (r) => r._measurement == "energy" and (r._field == "consumption" or r._field == "production"))',
' |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")'
].join('\n');;
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