javascriptinfluxdbfluxflux-influxdb

InfluxDB - query for current week


How can I use the boundaries.week() LINK function from the "@influxdata/influxdb-client"?

The docs say I need to import import "date/boundaries but I don't know where.

I need to query the current week from Monday to now.

Here my current query:

const weeklyPowerQuery = `
    from(bucket: "iobroker")
        |> range(start: -7d)
        |> filter(fn: (r) => r._measurement == "0_userdata.0.pv.dailyPower")
        |> filter(fn: (r) => r["_field"] == "value")
        `;


Solution

  • I have to put the import statement directly in the query string:

      const weeklyPowerQuery = `
            import "experimental/date/boundaries"
            lastWeek = boundaries.week(week_offset: -1)
            from(bucket: "io")
                |> range(start: -7d)
                |> filter(fn: (r) => r._measurement == "0_userdata.0.pv.dayPower")
                |> filter(fn: (r) => r["_field"] == "value")
              `;