Documentation

to() function

to() writes data to an InfluxDB Cloud or 2.x bucket and returns the written data.

Output data requirements

to() writes data structured using the standard InfluxDB Cloud and v2.x data structure that includes, at a minimum, the following columns:

  • _time
  • _measurement
  • _field
  • _value

All other columns are written to InfluxDB as tags.

Note: to() drops rows with null _time values and does not write them to InfluxDB.

to() does not require a package import

to() is part of the influxdata/influxdb package, but is part of the Flux prelude and does not require an import statement or package namespace.

Function type signature
(
    <-tables: stream[A],
    ?bucket: string,
    ?bucketID: string,
    ?fieldFn: (r: A) => B,
    ?host: string,
    ?measurementColumn: string,
    ?org: string,
    ?orgID: string,
    ?tagColumns: [string],
    ?timeColumn: string,
    ?token: string,
) => stream[A] where A: Record, B: Record

For more information, see Function type signatures.

Parameters

bucket

Name of the bucket to write to. bucket and bucketID are mutually exclusive.

bucketID

String-encoded bucket ID to to write to. bucket and bucketID are mutually exclusive.

host

URL of the InfluxDB instance to write to.

See InfluxDB Cloud regions or InfluxDB OSS URLs. host is required when writing to a remote InfluxDB instance. If specified, token is also required.

org

Organization name. org and orgID are mutually exclusive.

orgID

String-encoded organization ID to query. org and orgID are mutually exclusive.

token

InfluxDB API token.

InfluxDB 1.x or Enterprise: If authentication is disabled, provide an empty string (""). If authentication is enabled, provide your InfluxDB username and password using the <username>:<password> syntax. token is required when writing to another organization or when host is specified.

timeColumn

Time column of the output. Default is "_time".

measurementColumn

Measurement column of the output. Default is "_measurement".

tagColumns

Tag columns in the output. Defaults to all columns with type string, excluding all value columns and columns identified by fieldFn.

fieldFn

Function that maps a field key to a field value and returns a record. Default is (r) => ({ [r._field]: r._value }).

tables

Input data. Default is piped-forward data (<-).

Examples

Write data to InfluxDB

data =
    array.from(
        rows: [
            {
                _time: 2021-01-01T00:00:00Z,
                _measurement: "m",
                tag1: "a",
                _field: "temp",
                _value: 100.1,
            },
            {
                _time: 2021-01-01T00:01:00Z,
                _measurement: "m",
                tag1: "a",
                _field: "temp",
                _value: 99.8,
            },
            {
                _time: 2021-01-01T00:02:00Z,
                _measurement: "m",
                tag1: "a",
                _field: "temp",
                _value: 99.1,
            },
            {
                _time: 2021-01-01T00:03:00Z,
                _measurement: "m",
                tag1: "a",
                _field: "temp",
                _value: 98.6,
            },
        ],
    )

data
    |> to(
        bucket: "example-bucket",
        org: "example-org",
        token: "mYSuP3rSecR37t0k3N",
        host: "http://localhost:8086",
    )

The example above produces the following line protocol and sends it to the InfluxDB /api/v2/write endpoint:

m,tag1=a temp=100.1 1609459200000000000
m,tag1=a temp=99.8 1609459260000000000
m,tag1=a temp=99.1 1609459320000000000
m,tag1=a temp=98.6 1609459380000000000

Customize measurement, tag, and field columns in the to() operation

data =
    array.from(
        rows: [
            {
                _time: 2021-01-01T00:00:00Z,
                tag1: "a",
                tag2: "b",
                hum: 53.3,
                temp: 100.1,
            },
            {
                _time: 2021-01-01T00:01:00Z,
                tag1: "a",
                tag2: "b",
                hum: 53.4,
                temp: 99.8,
            },
            {
                _time: 2021-01-01T00:02:00Z,
                tag1: "a",
                tag2: "b",
                hum: 53.6,
                temp: 99.1,
            },
            {
                _time: 2021-01-01T00:03:00Z,
                tag1: "a",
                tag2: "b",
                hum: 53.5,
                temp: 98.6,
            },
        ],
    )

data
    |> to(
        bucket: "example-bucket",
        measurementColumn: "tag1",
        tagColumns: ["tag2"],
        fieldFn: (r) => ({"hum": r.hum, "temp": r.temp}),
    )

The example above produces the following line protocol and sends it to the InfluxDB /api/v2/write endpoint:

a,tag2=b hum=53.3,temp=100.1 1609459200000000000
a,tag2=b hum=53.4,temp=99.8 1609459260000000000
a,tag2=b hum=53.6,temp=99.1 1609459320000000000
a,tag2=b hum=53.5,temp=98.6 1609459380000000000

Write to multiple InfluxDB buckets

The example below does the following:

  1. Writes data to bucket1 and returns the data as it is written.
  2. Applies an empty group key to group all rows into a single table.
  3. Counts the number of rows.
  4. Maps columns required to write to InfluxDB.
  5. Writes the modified data to bucket2.
data
    |> to(bucket: "bucket1")
    |> group()
    |> count()
    |> map(
        fn: (r) => ({r with _time: now(), _measurement: "writeStats", _field: "numPointsWritten"}),
    )
    |> to(bucket: "bucket2")

Was this page helpful?

Thank you for your feedback!


InfluxDB OSS 2.9.0: API tokens are hashed by default

Stronger token security in InfluxDB OSS 2.9.0 — tokens are hashed on disk by default. Existing tokens are hashed on first startup and can’t be recovered afterward. Capture any plaintext tokens you still need before you upgrade.

View InfluxDB OSS 2.9.0 release notes

Hashed tokens authenticate exactly like unhashed tokens — clients and integrations keep working.

Also new in 2.9.0:

  • Configurable backup compression
  • Restore support for backups containing hashed tokens
  • Tighter Edge Data Replication queue validation
  • Flux upgrade
  • Compaction reliability improvements

Key enhancements in Explorer 1.8

Explorer 1.8 is now available with streaming data subscriptions (beta), line protocol preview, and query history & saved queries.

View Explorer 1.8 release notes

Explorer 1.8 includes new features and improvements that make it easier to ingest, explore, and manage data.

Highlights:

  • Streaming data subscriptions (beta): Stream data into Explorer from MQTT, Kafka, and AMQP sources.
  • Line protocol preview: Preview line protocol, schema, and parse errors before data is written.
  • Custom sample data: Generate custom sample datasets with line protocol and schema preview.
  • Query history and saved queries: Browse query history and save/re-run named queries.
  • Retention period management: Set, update, or clear retention periods on databases and tables.

For more details, see Explorer 1.8 release notes

InfluxDB 3.10 is now available

InfluxDB 3 Core 3.10 adds an automatic catalog format upgrade, a configurable query-concurrency limit, and processing engine improvements.

Key updates in InfluxDB 3 Core 3.10:

  • Catalog format upgrade: the on-disk catalog automatically upgrades from format v2 to v3 on first 3.10 startup. Migration is one-way—back up your catalog before upgrading.
  • --max-concurrent-queries: limit concurrent queries (adjustable at runtime).
  • GET /ready endpoint for readiness probes.
  • Processing engine: cross-database queries and trigger lockdown flags.

For more information, see the InfluxDB 3 Core release notes.

InfluxDB 3.10 is now available

InfluxDB 3 Enterprise 3.10 adds automated backup and restore, row-level deletions, and user management, with an automatic catalog format upgrade and performance preview improvements.

Key updates in InfluxDB 3 Enterprise 3.10:

  • Catalog format upgrade: the on-disk catalog automatically upgrades from format v2 to v3 on first 3.10 startup. Migration is one-way—back up your catalog before upgrading.
  • Automated backup and restore (beta)
  • Row-level deletions
  • User management (authentication and RBAC) — preview
  • Performance preview improvements

Backup and restore, row-level deletions, and the performance preview require the Enterprise storage engine upgrade (opt-in beta). Beta and preview features are subject to breaking changes and aren’t recommended for production use.

For more information, see the InfluxDB 3 Enterprise release notes

Telegraf Enterprise now in public beta

Get early access to the Telegraf Controller and provide feedback to help shape the future of Telegraf Enterprise.

See the Blog Post

The upcoming Telegraf Enterprise offering is for organizations running Telegraf at scale and is comprised of two key components:

  • Telegraf Controller: A control plane (UI + API) that centralizes Telegraf configuration management and agent health visibility.
  • Telegraf Enterprise Support: Official support for Telegraf Controller and Telegraf plugins.

Join the Telegraf Enterprise beta to get early access to the Telegraf Controller and provide feedback to help shape the future of Telegraf Enterprise.

For more information:

Telegraf Controller v0.0.7-beta now available

Telegraf Controller v0.0.7-beta is now available with new features, improvements, bug fixes, and an important breaking change.

View the release notes
Download Telegraf Controller v0.0.7-beta

InfluxDB Docker latest tag changing to InfluxDB 3 Core

On September 15, 2026, the latest tag for InfluxDB Docker images will point to InfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags in your Docker deployments.

If using Docker to install and run InfluxDB, the latest tag will point to InfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags in your Docker deployments. For example, if using Docker to run InfluxDB v2, replace the latest version tag with a specific version tag in your Docker pull command–for example:

docker pull influxdb:2