Query from Influxdb

Hi friends. I need your supports.

I'm trying to get data from Influx Cloud DB.

Table influxdb:

I use influxdb in node[v2.0] due to "influxdb cloud".

Contain node like below.

from(bucket: "NodeRed")
|> range(start: -1s)
|> filter(fn: (r) => r["_measurement"] == "myData" and r["_field"] == "Makine" and r["_value"] == "M3")
|> sort(columns: ["_time"], desc: true)
|> limit(n: 1)

But it's not useful. After debugging in nodered, rows containing M2 and M3 are also coming. I want to get only the last row containing the M3 value from Influxdb.

In addition I cannot use below query with influxdb in node[v2.0]. I think v2.0 only works with flux query.

"SELECT *
FROM "myData"
WHERE
("Makine" == 'M3')
order by timestamp desc
limit 1"

1- How can I get contain M3 last row with flux query?
2- Is there alternative using above SQL query in nodered?

Thanks in advance.

I believe that Makine must be a tag (not a field) then you can Group by it to select just the ones you want.

1 Like

Hi Colin. Thanks for your idea.

The following query solved my problem.

As in SQL, it returns last complete row containing M3.

from(bucket: "NodeRED")
|> range(start: -1m)
|> filter(fn: (r) => r["_measurement"] == "myData")
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
|> filter(fn:(r) => r.Makine == "M3")
|> limit(n:1)

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