# Sync mongodb data to elasticsearch(update if exists or insert) using logstash

**URL:** <https://discuss.elastic.co/t/sync-mongodb-data-to-elasticsearch-update-if-exists-or-insert-using-logstash/206897>\
**Category:** Logstash\
**Created:** [November 7, 2019, 6:03am UTC](https://discuss.elastic.co/t/sync-mongodb-data-to-elasticsearch-update-if-exists-or-insert-using-logstash/206897 "2019-11-07T06:03:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hannu98](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@hannu98](https://discuss.elastic.co/u/hannu98)\
**Post date:** [November 7, 2019, 6:03am UTC](https://discuss.elastic.co/t/sync-mongodb-data-to-elasticsearch-update-if-exists-or-insert-using-logstash/206897/1 "2019-11-07T06:03:42Z")

</div>

I just want to sync the data from mongodb to elastic using logstash. Its working good, when any new record comes in mongodb, logstash pushes into elastic. But when I update any record in mongodb then it does not change into elasticsearch. I want to make changes in the config file so that when any record updates in mongo it should reflect in elastic as well.

I have already tried by making action =\> "index" as well as action =\>"update" in .conf file.

Here is my mongodata.conf file

```auto
input{
 mongodb{
   uri => 'mongodb://localhost:27017/DBname'

   placeholder_db_dir => '/opt/logstash'
   placeholder_db_name => 'logstash_sqlite.db'
   collection => "collectionName"
   batch_size => 500
   }
  }

filter {
 mutate {
  remove_field => ["_id"]
 }
}

output{
    elasticsearch{
            action => "index"
            hosts => ["localhost:9200"]
            index => "mongo_hi_log_data"
    }
    stdout{ codec => rubydebug }
  }

**I want to sync the data from mongodb to elastic using logstash when any record is updated or inserted in mongodb**
```

---

<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:** [December 5, 2019, 6:03am UTC](https://discuss.elastic.co/t/sync-mongodb-data-to-elasticsearch-update-if-exists-or-insert-using-logstash/206897/2 "2019-12-05T06:03:43Z")

</div>

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