How to pass dynamic influxdb query input filter?

I am using node-red-contrib-influxdb
I want to pass dynamic deviceId selected from dashboard(coming in msg.deviceId) to below query field deviceId. How to achive this?

msg.query=`from(bucket: "localnrf")
  |> range(start: -2d)
  |> filter(fn: (r) => r["_measurement"] == "testdata")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["deviceId"] == "nrf-352656106122685")
  |> filter(fn: (r) => r["type"] == "TEMP")` ;
return msg;

You can embed the id in the message using javascript template literals. So something like

msg.query=`from(bucket: "localnrf")
  |> range(start: -2d)
  |> filter(fn: (r) => r["_measurement"] == "testdata")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["deviceId"] == ${msg.deviceId})
  |> filter(fn: (r) => r["type"] == "TEMP")` ;
1 Like

Thanks I will try this solution.

This is the correct solution:

msg.query=`from(bucket: "localnrf")
  |> range(start: -5m)
  |> filter(fn: (r) => r["_measurement"] == "testdata")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["deviceId"] == "${msg.deviceID}")
  |> filter(fn: (r) => r["type"] == "TEMP")` ;

Is that different to the suggestion I posted? I am on my phone and can't see the difference.

docule quote was missing which causing error${msg.deviceId}) >> "${msg.deviceId})"

Ah yes, you are right.

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