# Logstash-input-mongodb (questions)

**URL:** https://discuss.elastic.co/t/logstash-input-mongodb-questions/173363
**Category:** Logstash
**Created:** [March 21, 2019, 5:36pm UTC](https://discuss.elastic.co/t/logstash-input-mongodb-questions/173363 "2019-03-21T17:36:05Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![pmarques](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmarques/32/42536_2.png) [@pmarques](https://discuss.elastic.co/u/pmarques)
#### Post date: [March 21, 2019, 5:36pm UTC](https://discuss.elastic.co/t/logstash-input-mongodb-questions/173363/1 "2019-03-21T17:36:05Z")

</div>

Hello All,

I have read some old discussions about using MongoDB as a data source. I mean, using Logstash to bring data from MongoDB and send it to Elasticsearch. Basically, this ([MongoDB Logstash Integration [Solved]](https://discuss.elastic.co/t/mongodb-logstash-integration-solved/122299)) is the start point.

However, I have some questions:

- Why there is no official logstash-input-mongodb plugin?
- If not, is there the development of this plugin in the roadmap?
- What would be the best way to bring a "slice" of data from MongoDB to Elasticsearch?
- Is there any logstash-input-mongodb current updated?
- Any way to run db.collection.aggregate against MongoDB and send the result to Elasticsearch?

Thank you in advance for any information,

Paulo

---

<div class="post-metadata">

### Author: ![panda2004](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panda2004/32/19473_2.png) [@panda2004](https://discuss.elastic.co/u/panda2004)
#### Post date: [March 21, 2019, 7:34pm UTC](https://discuss.elastic.co/t/logstash-input-mongodb-questions/173363/2 "2019-03-21T19:34:24Z")

</div>

Hey @pmarques.

- As far as I know, there is no official logstash MongoDB Input plugin. But, there is an official [MongoDB output plugin](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-mongodb.html).  
Concerning your question ,much of the power of open source comes from its community, so I think that it's okay that the community develop its own plugins, support them and embrace them. Elastic already developed more than 200 [plugins](https://github.com/logstash-plugins). I did found an official unmaintained mongodb [plugin](https://github.com/logstash-plugins/logstash-input-mongodb). But why developing 2 repositories for the same task?

- Logstash is based on pulling data. Therefore, I used the JDBC input plugin since it support scheduling for finding new rows/events by using **[rufus-scheduler](https://github.com/jmettraux/rufus-scheduler)**. You can also use logstash http puller inupt , which also support scheduling, and exposing a [REST service](https://docs.mongodb.com/ecosystem/tools/http-interfaces/) for your MongoDB.  
Other alternative might be pushing data. [Here's](https://stackoverflow.com/questions/9691316/how-to-listen-for-changes-to-a-mongodb-collection) a collection of various mechanisms.

- Probably it depends whether the JDBC Input plugin and the MongoDB connector supports the aggregation functions. But i'm pretty sure that the REST service fully supports MongoDB features.

---

<div class="post-metadata">

### Author: ![pmarques](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmarques/32/42536_2.png) [@pmarques](https://discuss.elastic.co/u/pmarques)
#### Post date: [March 21, 2019, 8:34pm UTC](https://discuss.elastic.co/t/logstash-input-mongodb-questions/173363/3 "2019-03-21T20:34:45Z")

</div>

Hello @panda2004,

Thank you for your answer. I was thinking if there is a lack of NoSQL input plugins. I didn't find for Casandra either.

My solution for a while is a shell script wrapping a mongo shell + javascript (mongo -eval...), the problem here is that the full process takes 6.5 hours.

If it comes out any other idea, I will be pleased to share.

Cheers,  
Paulo

---

<div class="post-metadata">

### Author: ![panda2004](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panda2004/32/19473_2.png) [@panda2004](https://discuss.elastic.co/u/panda2004)
#### Post date: [March 23, 2019, 11:00am UTC](https://discuss.elastic.co/t/logstash-input-mongodb-questions/173363/4 "2019-03-23T11:00:34Z")

</div>

If you just need one-time import of data, that's also a good input plugin:

> **[phutchins/logstash-input-mongodb](https://github.com/phutchins/logstash-input-mongodb)**
>
> MongoDB input plugin for Logstash. Contribute to phutchins/logstash-input-mongodb development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![pmarques](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmarques/32/42536_2.png) [@pmarques](https://discuss.elastic.co/u/pmarques)
#### Post date: [March 24, 2019, 6:20pm UTC](https://discuss.elastic.co/t/logstash-input-mongodb-questions/173363/5 "2019-03-24T18:20:52Z")

</div>

Hello @panda2004,

Thank you for the suggestion. I have already tried [this](https://github.com/phutchins/logstash-input-mongodb)... This plugin is not well maintained and works well for bringing the whole collection. However, I need to bring a slice of it.

I will later publish my humble solution here.

Cheers,  
Paulo

---

<div class="post-metadata">

### Author: ![pmarques](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmarques/32/42536_2.png) [@pmarques](https://discuss.elastic.co/u/pmarques)
#### Post date: [April 9, 2019, 3:09pm UTC](https://discuss.elastic.co/t/logstash-input-mongodb-questions/173363/6 "2019-04-09T15:09:58Z")

</div>

Hello all,

Sorry for the delay.

As I mentioned before the idea was having a baby step before pushing data to Elasticsearch. So, I wrapped a MongoDB query in a shell script which receives all parameter I need. The mongo query saves a CSV file which is handled by Logstash.

The query is something like:

mongo --quiet --host localhost --port 27017 DBNAME --eval variable=VALUE JAVASCRIPT \> output.csv

JAVASCRIPT is a script where happens the query and manipulates the data. The JAVASCRIPT just needs to print the data for saving the CSV.

Cheers,  
Paulo

---

<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: [May 7, 2019, 3:10pm UTC](https://discuss.elastic.co/t/logstash-input-mongodb-questions/173363/7 "2019-05-07T15:10:09Z")

</div>

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