# How to Ingest data from MongoDB database into ElasticSearch using Logstash

**URL:** https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245
**Category:** Logstash
**Created:** [January 23, 2020, 12:52pm UTC](https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245 "2020-01-23T12:52:36Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jskishor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jskishor/32/61282_2.png) [@jskishor](https://discuss.elastic.co/u/jskishor)
#### Post date: [January 23, 2020, 12:52pm UTC](https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245/1 "2020-01-23T12:52:36Z")

</div>

Hello Logstash/ES Gurus,

I am new to ES and logstash, I need help on ingesting a user collection data from a mongo database into elastic search.

I have used logstash-input-mongodb plugin and started the logstash and it failed with following error though the error out line in config file looks good.

C:\>logstash-6.7.0\bin\logstash.bat -f logstash-6.7.0\config\logstash-mongo.conf  
Sending Logstash logs to C:/logstash-6.7.0/logs which is now configured via log4j2.properties  
[2020-01-23T18:14:06,538][WARN][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified  
[2020-01-23T18:14:06,557][INFO][logstash.runner] Starting Logstash {"logstash.version"=\>"6.7.0"}  
[2020-01-23T18:14:07,479][ERROR][logstash.agent] **Failed to execute action {:action=\>LogStash::PipelineAction::Create/pipeline\_id:main, :exception=\>"LogStash::ConfigurationError", :message=\>"Expected one of #, { at line 2, column 7 (byte 16) after input {\r\n uri "**, :backtrace=\>["C:/logstash-6.7.0/logstash-core/lib/logstash/compiler.rb:4

Below is how my config file looks  
input {  
uri =\> 'mongodb://:@\<mongo\_host\>:/?replicaSet=vncdev?ssl=true'  
placeholder\_db\_dir =\> '/opt/logstash-mongodb/'  
placeholder\_db\_name =\> 'logstash\_sqlite.db'  
collection =\> 'testcases'  
batch\_size =\> 5000  
}  
filter {

}  
output {  
stdout {  
codec =\> rubydebug  
}  
elasticsearch {  
action =\> "index"  
index =\> "mongo\_vncdev\_vncmgr"  
hosts =\> ["[http://localhost:9200](http://localhost:9200)"]  
}  
}

Any help in fixing is highly appreciated

Thanks  
Kishore

---

<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: [January 23, 2020, 1:41pm UTC](https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245/2 "2020-01-23T13:41:00Z")

</div>

Try

```
input {
    mongodb {
        uri => 'mongodb://:@<mongo_host>:/?replicaSet=vncdev?ssl=true'
        placeholder_db_dir => '/opt/logstash-mongodb/'
        placeholder_db_name => 'logstash_sqlite.db'
        collection => 'testcases'
        batch_size => 5000
    }
}
```

---

<div class="post-metadata">

### Author: ![jskishor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jskishor/32/61282_2.png) [@jskishor](https://discuss.elastic.co/u/jskishor)
#### Post date: [January 24, 2020, 10:02am UTC](https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245/3 "2020-01-24T10:02:41Z")

</div>

Hi Badger,

Thanks for the input, I am able to bypass the error after placing mongodb keyword after input as you mentioned.

I encountered additional error due to non-existance path /opt/logstash-mongodb.  
My mongodb is on a RHEL 7 VM, what path should I mention for placeholder\_db\_dir and placeholder\_db\_name

[2020-01-24T12:45:41,971][ERROR][logstash.pipeline] Error registering plugin {:pipeline\_id=\>"main", :plugin=\>"\<LogStash::Inputs::MongoDB placeholder\_db\_name=\>"logstash\_sqlite.db", collection=\>"testcases", batch\_size=\>5000, id=\>"acf2b106554f69e4310e9b934c64f14f396eedf391b6f6d201ad56c89de37da2", uri=\>"mongodb://vncmgr:vnc22019@xsj-dvdbvnc02:27060/vncreg?replicaSet=vncdev", placeholder\_db\_dir=\>"/opt/logstash-mongodb/", enable\_metric=\>true, codec=\>\<LogStash::Codecs::Plain id=\>"plain\_47a8a380-777a-4cec-86af-5099c36f6b89", enable\_metric=\>true, charset=\>"UTF-8"\>, since\_table=\>"logstash\_since", since\_column=\>"\_id", since\_type=\>"id", parse\_method=\>"flatten", isodate=\>false, retry\_delay=\>3, generateId=\>false, unpack\_mongo\_id=\>false, message=\>"Default message...", interval=\>1\>", **:error=\>"Java::JavaSql::SQLException: path to '/opt/logstash-mongodb/logstash\_sqlite.db': 'C:\opt' does not exist",** :thread=\>"#\<Thread:0x3bcff4ef run\>"}

Thanks  
Kishore

---

<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: [January 24, 2020, 1:45pm UTC](https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245/4 "2020-01-24T13:45:55Z")

</div>

> [@jskishor](#):
>
> error=\>"Java::JavaSql::SQLException: path to '/opt/logstash-mongodb/logstash\_sqlite.db': 'C:\opt' does not exist"

You need to set the placeholder path to a directory that exists on your computer.

---

<div class="post-metadata">

### Author: ![jskishor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jskishor/32/61282_2.png) [@jskishor](https://discuss.elastic.co/u/jskishor)
#### Post date: [January 27, 2020, 2:33pm UTC](https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245/5 "2020-01-27T14:33:34Z")

</div>

I am able to resolve the issue after placing the value of placeholder\_db\_dir to my local directory. Thanks for your help.

---

<div class="post-metadata">

### Author: ![SanTiaGo\_KarThiCk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/santiago_karthick/32/62188_2.png) [@SanTiaGo\_KarThiCk](https://discuss.elastic.co/u/SanTiaGo_KarThiCk)
#### Post date: [February 6, 2020, 10:53am UTC](https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245/6 "2020-02-06T10:53:47Z")

</div>

i am using logstash 7.5.2 and trying to connect mongodb using JDBC driver but cant find the suitable driver across the unity, progress (third party drivers)

---

<div class="post-metadata">

### Author: ![jskishor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jskishor/32/61282_2.png) [@jskishor](https://discuss.elastic.co/u/jskishor)
#### Post date: [February 6, 2020, 12:33pm UTC](https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245/7 "2020-02-06T12:33:22Z")

</div>

Go to logstash/bin folder and list the plugins using the command (

Example on windows:

logstash-plugin.bat list

logstash-plugin.bat install logstash-input-mongodb

---

<div class="post-metadata">

### Author: ![SanTiaGo\_KarThiCk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/santiago_karthick/32/62188_2.png) [@SanTiaGo\_KarThiCk](https://discuss.elastic.co/u/SanTiaGo_KarThiCk)
#### Post date: [February 7, 2020, 4:49am UTC](https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245/8 "2020-02-07T04:49:14Z")

</div>

i done with a logstash-input-mongodb plugin method but i cant connnect via JDBC driver(logstash-input-jdbc)

---

<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: [March 6, 2020, 4:49am UTC](https://discuss.elastic.co/t/how-to-ingest-data-from-mongodb-database-into-elasticsearch-using-logstash/216245/9 "2020-03-06T04:49:18Z")

</div>

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