# Using variables in a Influx node

**URL:** https://discourse.nodered.org/t/using-variables-in-a-influx-node/89143
**Category:** General
**Created:** [1 July 2024 12:46 UTC](https://discourse.nodered.org/t/using-variables-in-a-influx-node/89143 "2024-07-01T12:46:20Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![simmoinard](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@simmoinard](https://discourse.nodered.org/u/simmoinard)
#### Post date: [1 July 2024 12:46 UTC](https://discourse.nodered.org/t/using-variables-in-a-influx-node/89143/1 "2024-07-01T12:46:20Z")

</div>

Hi everyone,  
I'm sorry if this topic has been already discussed but I couldn't find anything (I think I don't have the good keywords...)

I have a (easy) flow with a MQTT IN node, then stores it directly in a node Influx.

I would like to change of database depending on the message received. The database name could be a variable "msg.payload.database", given by a function before.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c0e31e637cfcd2a682d408b828d765b493f1c37e.png)

But if I do this, the node will search the database named "msg.payload.database" (it doesn't recognise it as a variable...)

```auto
HttpError: 404 Not Found : {"error":"database not found: \"msg.payload.dbname\""}

```

Is this kind of thing possible ? Is there a way ?

---

<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: [1 July 2024 13:07 UTC](https://discourse.nodered.org/t/using-variables-in-a-influx-node/89143/2 "2024-07-01T13:07:33Z")

</div>

It don't believe it is possible to dynamically change the database. The measurement can, of course, be passed in the message.

If you need to do this I think you will have to access influxdb directly using http nodes to drive the influxdb api, which I believe is not difficult.

Alternatively, if you have a small set of databases, setup a node for each one and route the message to the appropriate one based on the message contents, using msg.database, for example.

---

<div class="post-metadata">

### Author: ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)
#### Post date: [1 July 2024 13:18 UTC](https://discourse.nodered.org/t/using-variables-in-a-influx-node/89143/3 "2024-07-01T13:18:55Z")

</div>

I don't use the Influx Nodes, however, I do use a Function Node to route the data to the databases and then an HTTP Request Node passing the parameters through messages (As Colin says!)

Basically, I send `msg.url` and `msg.payload` (containing the data) to a blank HTTP Request Node...

```auto
let str1 = msg.payload.measurement;
let str2 = msg.payload.timestamp;

if ((str1 == "temperature") || (str1 == "humidity") || (str1 == "Other") || (str1 == "bme680")) {
    msg.url = "http://localhost:8086/write?db=logs&precision=s";
}

```

---

<div class="post-metadata">

### Author: ![simmoinard](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@simmoinard](https://discourse.nodered.org/u/simmoinard)
#### Post date: [2 July 2024 05:56 UTC](https://discourse.nodered.org/t/using-variables-in-a-influx-node/89143/4 "2024-07-02T05:56:13Z")

</div>

Thank you @Colin ans @mudwalker ! I will try the HTTP way to "bypass" the Influx node.

Juste a small question, is it possible to do it with the Mqtt in node ? I can have Dynamic suscription to topics, but is it possible to have a Dynamic connexion to différent brokers ?

---

<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: [2 July 2024 06:08 UTC](https://discourse.nodered.org/t/using-variables-in-a-influx-node/89143/5 "2024-07-02T06:08:34Z")

</div>

> [@simmoinard](#):
>
> Dynamic connexion to différent brokers ?

Yes, read the help text for the node.

---

<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: [30 September 2024 06:09 UTC](https://discourse.nodered.org/t/using-variables-in-a-influx-node/89143/6 "2024-09-30T06:09:34Z")

</div>

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