to() function

Warning! This page documents an earlier version of Flux, which is no longer actively developed. Flux v0.65 is the most recent stable version of Flux.

The to() function writes data to an InfluxDB v2.0 bucket.

Function type: Output
Output data type: Object

  bucket: "my-bucket",
  org: "my-org",
  timeColumn: "_time",
  tagColumns: ["tag1", "tag2", "tag3"],
  fieldFn: (r) => ({ [r._field]: r._value })

// OR

  bucketID: "1234567890",
  orgID: "0987654321",
  timeColumn: "_time",
  tagColumns: ["tag1", "tag2", "tag3"],
  fieldFn: (r) => ({ [r._field]: r._value })


You must provide a bucket or bucketID and an org or orgID.


The bucket to write data to. bucket and bucketID are mutually exclusive.

Data type: String


The ID of the bucket to write data to. bucketID and bucket are mutually exclusive.

Data type: String


The organization name of the specified bucket. org and orgID are mutually exclusive.

Data type: String


The organization ID of the specified bucket. Only required when writing to a remote host. Mutually exclusive with org.

Data type: String


The time column of the output. Default is "_time".

Data type: String


The tag columns of the output. Defaults to all columns with type string, excluding all value columns and the _field column if present.

Data type: Array of strings


Function that takes a record from the input table and returns an object. For each record from the input table, fieldFn returns an object that maps output the field key to the output value. Default is (r) => ({ [r._field]: r._value }).

Data type: Function Output data type: Object

Make sure fieldFn parameter names match each specified parameter. To learn why, see Match parameter names.


Default to() operation

Given the following table:

_time _start _stop _measurement _field _value
0005 0000 0009 “a” “temp” 100.1
0006 0000 0009 “a” “temp” 99.3
0007 0000 0009 “a” “temp” 99.9

The default to operation:

// ...
|> to(bucket:"my-bucket", org:"my-org")

is equivalent to writing the above data using the following line protocol:

_measurement=a temp=100.1 0005
_measurement=a temp=99.3 0006
_measurement=a temp=99.9 0007

Custom to() operation

The to() functions default operation can be overridden. For example, given the following table:

_time _start _stop tag1 tag2 hum temp
0005 0000 0009 “a” “b” 55.3 100.1
0006 0000 0009 “a” “b” 55.4 99.3
0007 0000 0009 “a” “b” 55.5 99.9

The operation:

// ...
|> to(bucket:"my-bucket", org:"my-org", tagColumns:["tag1"], fieldFn: (r) => return {"hum": r.hum, "temp": r.temp})

is equivalent to writing the above data using the following line protocol:

_tag1=a hum=55.3,temp=100.1 0005
_tag1=a hum=55.4,temp=99.3 0006
_tag1=a hum=55.5,temp=99.9 0007