# How to pass dynamic influxdb query input filter?

**URL:** <https://discourse.nodered.org/t/how-to-pass-dynamic-influxdb-query-input-filter/59361>\
**Category:** General\
**Tags:** function-node\
**Created:** [4 March 2022 12:26 UTC](https://discourse.nodered.org/t/how-to-pass-dynamic-influxdb-query-input-filter/59361 "2022-03-04T12:26:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![akashtalole](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/akashtalole/32/30002_2.png) [@akashtalole](https://discourse.nodered.org/u/akashtalole)\
**Post date:** [4 March 2022 12:26 UTC](https://discourse.nodered.org/t/how-to-pass-dynamic-influxdb-query-input-filter/59361/1 "2022-03-04T12:26:04Z")

</div>

I am using [node-red-contrib-influxdb](https://flows.nodered.org/node/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?

```auto
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;

```

---

<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:** [4 March 2022 13:57 UTC](https://discourse.nodered.org/t/how-to-pass-dynamic-influxdb-query-input-filter/59361/2 "2022-03-04T13:57:31Z")

</div>

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

```auto
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")` ;

```

---

<div class="post-metadata">

**Author:** ![akashtalole](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/akashtalole/32/30002_2.png) [@akashtalole](https://discourse.nodered.org/u/akashtalole)\
**Post date:** [4 March 2022 14:11 UTC](https://discourse.nodered.org/t/how-to-pass-dynamic-influxdb-query-input-filter/59361/3 "2022-03-04T14:11:53Z")

</div>

Thanks I will try this solution.

---

<div class="post-metadata">

**Author:** ![akashtalole](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/akashtalole/32/30002_2.png) [@akashtalole](https://discourse.nodered.org/u/akashtalole)\
**Post date:** [5 March 2022 02:33 UTC](https://discourse.nodered.org/t/how-to-pass-dynamic-influxdb-query-input-filter/59361/4 "2022-03-05T02:33:38Z")

</div>

This is the correct solution:

```auto
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")` ;

```

---

<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:** [5 March 2022 07:18 UTC](https://discourse.nodered.org/t/how-to-pass-dynamic-influxdb-query-input-filter/59361/5 "2022-03-05T07:18:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![akashtalole](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/akashtalole/32/30002_2.png) [@akashtalole](https://discourse.nodered.org/u/akashtalole)\
**Post date:** [5 March 2022 07:27 UTC](https://discourse.nodered.org/t/how-to-pass-dynamic-influxdb-query-input-filter/59361/6 "2022-03-05T07:27:24Z")

</div>

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

---

<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:** [5 March 2022 07:41 UTC](https://discourse.nodered.org/t/how-to-pass-dynamic-influxdb-query-input-filter/59361/7 "2022-03-05T07:41:07Z")

</div>

Ah yes, you are right.

---

<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:** [19 March 2022 07:41 UTC](https://discourse.nodered.org/t/how-to-pass-dynamic-influxdb-query-input-filter/59361/8 "2022-03-19T07:41:53Z")

</div>

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