# Telegraf...specify influxdb database per mqtt input?

**URL:** <https://community.influxdata.com/t/telegraf-specify-influxdb-database-per-mqtt-input/23396>\
**Category:** Telegraf\
**Tags:** influxdb, mqtt\
**Created:** [January 16, 2022, 9:13pm UTC](https://community.influxdata.com/t/telegraf-specify-influxdb-database-per-mqtt-input/23396 "2022-01-16T21:13:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hansij66](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hansij66/32/9249_2.png) [@hansij66](https://community.influxdata.com/u/hansij66)\
**Post date:** [January 16, 2022, 9:13pm UTC](https://community.influxdata.com/t/telegraf-specify-influxdb-database-per-mqtt-input/23396/1 "2022-01-16T21:13:00Z")

</div>

I have a few MQTT sources, some under my control, other “off the shelf”.

Typically, I want the various MQTT source data to land in its dedicated influxdb database.

In telegraf.conf, I use:

> [[outputs.influxdb]]  
> urls = [“[http://influxdb:8086](http://influxdb:8086)”]  
> database = “telegraf”  
> database\_tag = “database”

For the MQTT sources which I have control, I add a key:value - database:databasename1.

For MQTT sources which I don’'t have control, all ends up in database telegraf.

Is there anyway to fix this? Is there a way to specify per [[inputs.mqtt\_consumer]] input (which subscribes to a specific MQTT topic) the influxdb database (or insert an additional tag database:value?).

Thanks  
Hans

---

<div class="post-metadata">

**Author:** ![Franky1](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/franky1/32/6666_2.png) [@Franky1](https://community.influxdata.com/u/Franky1)\
**Post date:** [January 17, 2022, 9:14am UTC](https://community.influxdata.com/t/telegraf-specify-influxdb-database-per-mqtt-input/23396/2 "2022-01-17T09:14:35Z")

</div>

Welcome to the community!

Yes, this is possible in Telegraf and is called **metric filtering** , see here in the docs:

> [https://docs.influxdata.com/telegraf/v1/configuration/](https://docs.influxdata.com/telegraf/v1.21/administration/configuration/#metric-filtering)

Here is a simple example.

```toml
[[inputs.mqtt_consumer]]
# other plugin configs...
measurement_name = "mqtt_1"

[[inputs.mqtt_consumer]]
# other plugin configs...
measurement_name = "mqtt_2"

[[outputs.influxdb]]
# other plugin configs...
namepass = ["mqtt_1"]

[[outputs.influxdb]]
# other plugin configs...
namepass = ["mqtt_2"]

```

---

<div class="post-metadata">

**Author:** ![hansij66](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hansij66/32/9249_2.png) [@hansij66](https://community.influxdata.com/u/hansij66)\
**Post date:** [February 7, 2022, 3:01pm UTC](https://community.influxdata.com/t/telegraf-specify-influxdb-database-per-mqtt-input/23396/3 "2022-02-07T15:01:45Z")

</div>

Thanks, trigger email got lost in spam; I will give it a try asap!

---

<div class="post-metadata">

**Author:** ![Franky1](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/franky1/32/6666_2.png) [@Franky1](https://community.influxdata.com/u/Franky1)\
**Post date:** [February 7, 2022, 3:05pm UTC](https://community.influxdata.com/t/telegraf-specify-influxdb-database-per-mqtt-input/23396/4 "2022-02-07T15:05:14Z")

</div>

Or maybe try this even better solution:

> [@Influxdb\_v2 Output to different buckets doesn't work](https://community.influxdata.com/t/influxdb-v2-output-to-different-buckets-doesnt-work/23426/3):
>
> There is a better way to do that, use the bucket\_tag option of the InflxDB2 output (docs [here](https://github.com/influxdata/telegraf/tree/master/plugins/outputs/influxdb_v2#influxdb-v2x-output-plugin)) it allows you to specify the “routing” by using a tag value Here is a sample using your current config [[inputs.mqtt\_consumer]] servers = ["tcp://e\_mqtt:1883"] topics = ["Y/Schlafzimmer/power/SENSOR",] data\_format = "json" [inputs.mqtt\_consumer.tags] destination = "Ybucket" [[inputs.mqtt\_consumer]] servers = ["tcp://e\_mqtt:1883"] topics = [ "PowerMeter/001/power/SENSOR", "…
