Documentation

Write to InfluxDB

To write data to InfluxDB using Flux, use to() or experimental.to(). Provide the following parameters to both functions:

Write options

Write data to InfluxDB

Use to() to write data structured using the standard InfluxDB v2.x and InfluxDB Cloud data structure. Data must include, at a minimum, the following columns:

  • _time
  • _measurement
  • _field
  • _value

All other columns are written to InfluxDB as tags.

Given the following input stream of tables:

_time_measurementidloc_field_value
2021-01-01T00:00:00Zm001SFtemp72.1
2021-01-01T01:00:00Zm001SFtemp71.8
2021-01-01T02:00:00Zm001SFtemp71.2
_time_measurementidloc_field_value
2021-01-01T00:00:00Zm001SFhum40.5
2021-01-01T01:00:00Zm001SFhum50.1
2021-01-01T02:00:00Zm001SFhum52.8

to() generates the following line protocol and writes it to InfluxDB:

m,id=001,loc=SF temp=72.1,hum=40.5 1609459200000000000
m,id=001,loc=SF temp=71.8,hum=50.1 1609462800000000000
m,id=001,loc=SF temp=71.2,hum=52.8 1609466400000000000

Example: Write data to a bucket

data
    |> to(bucket: "example-bucket")
data
    |> to(bucket: "example-bucket", org: "example-org", token: "mY5uPeRs3Cre7tok3N")
data
    |> to(
        bucket: "example-bucket",
        org: "example-org",
        token: "mY5uPeRs3Cre7tok3N",
        host: "https://myinfluxdbdomain.com/8086",
    )

Write pivoted data to InfluxDB

Use experimental.to() to write pivoted data to InfluxDB. Input data must have the following columns:

  • _time
  • _measurement

All columns in the group key other than _time and _measurement are written to InfluxDB as tags. Columns not in the group key are written to InfluxDB as fields.

_start and _stop columns are ignored.

To write pivoted data to InfluxDB:

  1. Import the experimental package.
  2. Use experimental.to() to write pivoted data to an InfluxDB bucket.
import "experimental"

data
    |> experimental.to(bucket: "example-bucket")

Given the following input stream of tables:

Group key = [_measurement, id, loc]

_time_measurementidlocminmaxmean
2021-01-01T00:00:00Zm001FR264.0
2021-01-01T01:00:00Zm001FR21810.0
2021-01-01T02:00:00Zm001FR1137.0
_time_measurementidlocminmaxmean
2021-01-01T00:00:00Zm001BK444.0
2021-01-01T01:00:00Zm001BK354.0
2021-01-01T02:00:00Zm001BK586.5

experimental.to() generates the following line protocol and writes it to InfluxDB:

m,id=001,loc=FR min=2i,max=6i,mean=4 1609459200000000000
m,id=001,loc=FR min=2i,max=18i,mean=10 1609462800000000000
m,id=001,loc=FR min=1i,max=13i,mean=7 1609466400000000000
m,id=001,loc=BK min=4i,max=4i,mean=4 1609459200000000000
m,id=001,loc=BK min=3i,max=5i,mean=4 1609462800000000000
m,id=001,loc=BK min=5i,max=3i,mean=6.5 1609466400000000000

Example: Write pivoted data to InfluxDB

import "experimental"

data
    |> experimental.to(bucket: "example-bucket")
import "experimental"

data
    |> experimental.to(bucket: "example-bucket", org: "example-org", token: "mY5uPeRs3Cre7tok3N")
import "experimental"

data
    |> experimental.to(
        bucket: "example-bucket",
        org: "example-org",
        token: "mY5uPeRs3Cre7tok3N",
        host: "https://myinfluxdbdomain.com/8086",
    )

Was this page helpful?

Thank you for your feedback!


Linux Package Signing Key Rotation

All signed InfluxData Linux packages have been resigned with an updated key. If using Linux, you may need to update your package configuration to continue to download and verify InfluxData software packages.

For more information, see the Linux Package Signing Key Rotation blog post.

InfluxDB Cloud backed by InfluxDB IOx

All InfluxDB Cloud organizations created on or after January 31, 2023 are backed by the new InfluxDB IOx storage engine. Check the right column of your InfluxDB Cloud organization homepage to see which InfluxDB storage engine you’re using.

If powered by IOx, this is the correct documentation.

If powered by TSM, see the TSM-based InfluxDB Cloud documentation.

InfluxDB Cloud backed by InfluxDB TSM

All InfluxDB Cloud organizations created on or after January 31, 2023 are backed by the new InfluxDB IOx storage engine which enables nearly unlimited series cardinality and SQL query support. Check the right column of your InfluxDB Cloud organization homepage to see which InfluxDB storage engine you’re using.

If powered by TSM, this is the correct documentation.

If powered by IOx, see the IOx-based InfluxDB Cloud documentation.

State of the InfluxDB Cloud (IOx) documentation

The new documentation for InfluxDB Cloud backed by InfluxDB IOx is a work in progress. We are adding new information and content almost daily. Thank you for your patience!

If there is specific information you’re looking for, please submit a documentation issue.