# When output from logstash to mangodb, can I specify which fields wanted in output?

**URL:** <https://discuss.elastic.co/t/when-output-from-logstash-to-mangodb-can-i-specify-which-fields-wanted-in-output/300817>\
**Category:** Logstash\
**Created:** [March 28, 2022, 8:57am UTC](https://discuss.elastic.co/t/when-output-from-logstash-to-mangodb-can-i-specify-which-fields-wanted-in-output/300817 "2022-03-28T08:57:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maoxuguang](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@maoxuguang](https://discuss.elastic.co/u/maoxuguang)\
**Post date:** [March 28, 2022, 8:57am UTC](https://discuss.elastic.co/t/when-output-from-logstash-to-mangodb-can-i-specify-which-fields-wanted-in-output/300817/1 "2022-03-28T08:57:37Z")

</div>

I config two destination in logstash output, one is Elasticsearch, the other is mongodb. I only want to out put several fields to mongodb, not all of them. How to config to achieve that? Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 28, 2022, 2:44pm UTC](https://discuss.elastic.co/t/when-output-from-logstash-to-mangodb-can-i-specify-which-fields-wanted-in-output/300817/2 "2022-03-28T14:44:30Z")

</div>

You might be able to do it by specifying a format option on a codec, or by using pipeline to pipeline communication with a [forked path](https://www.elastic.co/guide/en/logstash/current/pipeline-to-pipeline.html#forked-path-pattern) pattern.

---

<div class="post-metadata">

**Author:** ![maoxuguang](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@maoxuguang](https://discuss.elastic.co/u/maoxuguang)\
**Post date:** [March 29, 2022, 10:35am UTC](https://discuss.elastic.co/t/when-output-from-logstash-to-mangodb-can-i-specify-which-fields-wanted-in-output/300817/3 "2022-03-29T10:35:32Z")

</div>

> [@Badger](#):
>
> do it by specifying a format option on a codec

could you give me an example? codec json has no format option. Here is my config:

```auto
mongodb {
      id => "my_mongodb_plugin_id"
      collection => "xxxxx"
      database => "xxxxx"
      uri => "mongodb://xx.xx.xx.xx:27017"
      codec => "json"
    }

```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 29, 2022, 2:56pm UTC](https://discuss.elastic.co/t/when-output-from-logstash-to-mangodb-can-i-specify-which-fields-wanted-in-output/300817/4 "2022-03-29T14:56:25Z")

</div>

If you need to use a json codec you would need to use a forked-path pattern to create a path that removes the fields that you do not want.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 26, 2022, 2:56pm UTC](https://discuss.elastic.co/t/when-output-from-logstash-to-mangodb-can-i-specify-which-fields-wanted-in-output/300817/5 "2022-04-26T14:56:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
