Using variables in a Influx node

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

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

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

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

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.

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...

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";
}
1 Like

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 ?

Yes, read the help text for the node.