# Error connecting to mongodb

**URL:** <https://discourse.nodered.org/t/error-connecting-to-mongodb/15127>\
**Category:** General\
**Created:** [4 September 2019 23:56 UTC](https://discourse.nodered.org/t/error-connecting-to-mongodb/15127 "2019-09-04T23:56:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickirea](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rickirea/32/11770_2.png) [@rickirea](https://discourse.nodered.org/u/rickirea)\
**Post date:** [4 September 2019 23:56 UTC](https://discourse.nodered.org/t/error-connecting-to-mongodb/15127/1 "2019-09-04T23:56:19Z")

</div>

when i configure a mongo node  
it shows the error as

"MongoError: failed to connect to server [127.0.0.1:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]"

I cannot connect to MongoDB to store the tweets.  
Help me with this.  
Thank you.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [5 September 2019 07:17 UTC](https://discourse.nodered.org/t/error-connecting-to-mongodb/15127/2 "2019-09-05T07:17:45Z")

</div>

please don’t flag the same issue in multiple threads.

There are many reasons for that error. Most are not to do with Node-RED but with your mongobd database.

These include mongodb is not running, it crashed and has a lock file you need to delete, the port is busy.

---

<div class="post-metadata">

**Author:** ![rickirea](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rickirea/32/11770_2.png) [@rickirea](https://discourse.nodered.org/u/rickirea)\
**Post date:** [5 September 2019 14:05 UTC](https://discourse.nodered.org/t/error-connecting-to-mongodb/15127/3 "2019-09-05T14:05:15Z")

</div>

There is not any issue with my mongo database as im using it with live applications, this occurs only with the node-red docker image, when i run locally it is working properly, so there is something missing with the docker image.

I was thinking this forum could help with some valuable and serious ideas. Not just to recommend google it.

Thanks any way.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [5 September 2019 14:21 UTC](https://discourse.nodered.org/t/error-connecting-to-mongodb/15127/4 "2019-09-05T14:21:42Z")

</div>

Is your mongo server allowing incoming traffic through (outgoing) docker containers? Say you were to get a shell into your running docker container, then call it manually. Does it run? If yes it might be a node-red issue. If no it might be a docker/mongo issue.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 September 2019 14:30 UTC](https://discourse.nodered.org/t/error-connecting-to-mongodb/15127/5 "2019-09-05T14:30:20Z")

</div>

You never mentioned docker in your original post so how are we to guess ? but yes - unless you have specifically opened up the necessary ports for mongo on your docker instance then the Node-RED mongo node won't be able to get out to make a connection.

---

<div class="post-metadata">

**Author:** ![rickirea](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rickirea/32/11770_2.png) [@rickirea](https://discourse.nodered.org/u/rickirea)\
**Post date:** [5 September 2019 14:37 UTC](https://discourse.nodered.org/t/error-connecting-to-mongodb/15127/6 "2019-09-05T14:37:44Z")

</div>

Thank you very much for sugest such a test, I will do.

---

<div class="post-metadata">

**Author:** ![rickirea](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rickirea/32/11770_2.png) [@rickirea](https://discourse.nodered.org/u/rickirea)\
**Post date:** [5 September 2019 14:39 UTC](https://discourse.nodered.org/t/error-connecting-to-mongodb/15127/7 "2019-09-05T14:39:54Z")

</div>

You right, I should have mentioned that I were running node-red on a docker image, I will validate if the ports are opened. Thansk so much for answer.
