# Elastic Search Connect to Mongo Database Server

**URL:** https://discuss.elastic.co/t/elastic-search-connect-to-mongo-database-server/125289
**Category:** Elasticsearch
**Created:** [March 23, 2018, 1:40am UTC](https://discuss.elastic.co/t/elastic-search-connect-to-mongo-database-server/125289 "2018-03-23T01:40:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Gehan\_Fernando](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gehan_fernando/32/29163_2.png) [@Gehan\_Fernando](https://discuss.elastic.co/u/Gehan_Fernando)
#### Post date: [March 23, 2018, 1:40am UTC](https://discuss.elastic.co/t/elastic-search-connect-to-mongo-database-server/125289/1 "2018-03-23T01:40:20Z")

</div>

basically, I know the difference between MongoDB and the ES. In my server I have installed MongoDB instance separately will name it as (MDB1) and I installed ES instance separately will name it as (ESS). Currently, I am working on document management system, daily storing millions different kind of document information in Mongo DB. I have browsed many websites but I didn't get my answer as expected.

My question is, I want to connect ESS to MDB1, coz I using ES to search and analyze the data. Is there have any method to connect ES to existing MongoDB instance. (I am using C#.net)

---

<div class="post-metadata">

### Author: ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)
#### Post date: [April 3, 2018, 10:59pm UTC](https://discuss.elastic.co/t/elastic-search-connect-to-mongo-database-server/125289/2 "2018-04-03T22:59:08Z")

</div>

There is no official connector from the Elasticsearch side. There are third-party connectors you can use. You can also do http bulk update queries to load data to ES.

---

<div class="post-metadata">

### Author: ![Gehan\_Fernando](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gehan_fernando/32/29163_2.png) [@Gehan\_Fernando](https://discuss.elastic.co/u/Gehan_Fernando)
#### Post date: [April 4, 2018, 12:45am UTC](https://discuss.elastic.co/t/elastic-search-connect-to-mongo-database-server/125289/3 "2018-04-04T00:45:26Z")

</div>

**Configure MongoDB on Elasticsearch**

1. Install MongoDB
2. Configure MongoDB

```auto
net:
    bindIp: 127.0.0.1
    port: 27017
replication:
    oplogSizeMB: 1024
    replSetName: res0
storage:
    dbPath: C:\data\db\rs0
systemLog:
    timeStampFormat: iso8601-utc
    destination: file
    path: C:\data\log\rs0\mongod.log

```

- Create two file using above configuration save it as `primary.cfg` and `secondary.cfg`.

- Install as Service:

```auto
mongod --config "C:\Program Files\MongoDB\Server\3.6\primary.cfg" --install --serviceName "MongoDB_Primary" --serviceDisplayName "MongoDB Primary"
mongod --config "C:\Program Files\MongoDB\Server\3.6\secondary.cfg" --install --serviceName "MongoDB_Secondary" --serviceDisplayName "MongoDB Secondary"

```

- Start services (Primary and Secondary instances):

1. Connect to the primary database
2. Use `rs.initiate()` command
3. Use `rs.add("127.0.0.1:27018")` command
4. Use `rs.config()` command
5. Use `rs.status()` command
6. Install Java latest version and set java home path in variable environment
7. Install Elasticsearch
8. Go to Elasticsearch folder and open config folder
9. Set following configuration in `elasticsearch.yml` file:

```auto
cluster.name: home_server
node.name: gehan-pc
path.data: C:\Elasticsearch\data
path.logs: C:\Elasticsearch\logs
network.host: 127.0.0.1
network.bind_host: 0.0.0.0
http.port: 9200
http.cors.enabled : true
http.cors.allow-origin : "*"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type, Content-Length

```

1. Install following files:

```auto
pip install mongo-connector[elastic5]
pip install elastic2-doc-manager[elastic5]

```

1. Start Elasticsearch instance
2. Run this command:

```auto
mongo-connector --auto-commit-interval=0 -d elastic_doc_manager -t localhost:9200

```

1. Open [http://localhost:9200/\_cat/indices?v](http://localhost:9200/_cat/indices?v) to check is mongo collections sync with Elasticsearch server

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [April 4, 2018, 6:52am UTC](https://discuss.elastic.co/t/elastic-search-connect-to-mongo-database-server/125289/4 "2018-04-04T06:52:40Z")

</div>

Thank you @Gehan_Fernando for sharing your recipe. I updated the format a bit as this can be useful for other members. I hope I did not change anything important (specifically, I updated a bit the mongo config).

---

<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 2, 2018, 6:52am UTC](https://discuss.elastic.co/t/elastic-search-connect-to-mongo-database-server/125289/5 "2018-05-02T06:52:51Z")

</div>

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