Documentation

MongoDB Output Plugin

This plugin writes metrics to MongoDB automatically creating collections as time series collections if they don’t exist.

This plugin requires MongoDB v5 or later for time series collections.

Introduced in: Telegraf v1.21.0 Tags: datastore OS support: all

Global configuration options

Plugins support additional global and plugin configuration settings for tasks such as modifying metrics, tags, and fields, creating aliases, and configuring plugin ordering. See CONFIGURATION.md for more details.

Secret-store support

This plugin supports secrets from secret-stores for the username and password option. See the secret-store documentation for more details on how to use them.

Configuration

# A plugin that can transmit logs to mongodb
[[outputs.mongodb]]
  ## Connection string
  ## example: dsn = "mongodb://mongod1:27017,mongod2:27017,mongod3:27017/admin&replicaSet=myReplSet&w=1"
  dsn = "mongodb://localhost:27017"

  ## Overrides serverSelectionTimeoutMS in DSN if set
  # timeout = "30s"

  ## Authentication method, available options are NONE, PLAIN, SCRAM, X509
  # authentication = "NONE"

  # ## for SCRAM-SHA-256 authentication
  # # authentication = "SCRAM"
  # # username = "root"
  # # password = "***"

  # ## for PLAIN authentication (e.g., LDAP)
  # ## IMPORTANT: PLAIN authentication sends credentials in plaintext during the
  # ## authentication handshake. Always use TLS to encrypt credentials in transit.
  # # authentication = "PLAIN"
  # # username = "myuser"
  # # password = "***"

  # ## X509 based certificate authentication
  # # authentication = "X509"
  # # tls_ca = "ca.pem"
  # # tls_key = "client.pem"
  # # # tls_key_pwd = "changeme" # required for encrypted tls_key
  # # insecure_skip_verify = false

  ## Database to store measurements and time series collections
  # database = "telegraf"

  ## Granularity can be seconds, minutes, or hours.
  ## Configuring this value will be based on your input collection frequency
  ## see https://docs.mongodb.com/manual/core/timeseries-collections/#create-a-time-series-collection
  # granularity = "seconds"

  ## TTL to automatically expire documents from the measurement collections.
  # ttl = "360h"

  ## If true, write multiple metrics for the same collection in a batched
  ## fashion. Otherwise, write each metric individually.
  # write_batch = false

Was this page helpful?

Thank you for your feedback!


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:

InfluxDB Docker latest tag changing to InfluxDB 3 Core

On May 27, 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