# MongoDB remote access

**URL:** <https://discourse.nodered.org/t/mongodb-remote-access/13014>\
**Category:** General\
**Created:** [7 July 2019 22:28 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014 "2019-07-07T22:28:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ljavih](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@ljavih](https://discourse.nodered.org/u/ljavih)\
**Post date:** [7 July 2019 22:28 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014/1 "2019-07-07T22:28:39Z")

</div>

HI I am using the node node-red-node-mongodb in order to do a remote connection to mongoDB and this error is display "MongoError: connection 507 to [pruebanodered-shard-00-00-mtmwd.mongodb.net:27017](http://pruebanodered-shard-00-00-mtmwd.mongodb.net:27017) closed".  
I already do the port test and the port is available and I also check the hostname and I am sure it is correct. Also I configure access in MongoAtlas in order to allow acces from anywhere and it still doesn't work. I have no idea what else I could do

---

<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:** [7 July 2019 22:33 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014/2 "2019-07-07T22:33:40Z")

</div>

Are the username and password double-checked? I’ve a setup like that on Atlas too (hate the access from everywhere part but with code running on the free heroku tier I can’t configure addresses sadly enough), though I don’t connect through NR. I might set it up like that tomorrow morning with that node to see if I can reproduce it.

---

<div class="post-metadata">

**Author:** ![ljavih](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@ljavih](https://discourse.nodered.org/u/ljavih)\
**Post date:** [8 July 2019 12:25 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014/3 "2019-07-08T12:25:36Z")

</div>

Yes I have check username and password, I am sure they are correct. I don't understand why this error is happening

---

<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:** [8 July 2019 14:01 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014/4 "2019-07-08T14:01:32Z")

</div>

@ljavih just reproduced it from my Atlas setup. I think I know what it is caused by, going to see if I can debug it.

---

<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:** [8 July 2019 14:15 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014/5 "2019-07-08T14:15:07Z")

</div>

It's caused by the following block of code:

> <https://github.com/node-red/node-red-nodes/blob/master/storage/mongodb/66-mongodb.js#L15-L19>

  
Newer versions of mongodb use the `authdb` to authorise against to the server, then switch to the database they interact on. This is handled through setting a parameter behind that url, `authSource=<authdb>`.  
The contrib node `node-red-contrib-mongodb3` actually solves this issue, switching to that node should do the trick.  

> **[node-red-contrib-mongodb3](https://flows.nodered.org/node/node-red-contrib-mongodb3)**
>
> MongoDB 3 driver node for Node-RED

Considering the `node-red-node-mongodb` describes itself as "connecting to a local mongodb database", I'm not sure if this would be considered a bug since this is something that mostly happens at hosted installs, though it will probably happen on home/local installs too if you follow the documentation on securing your install (which you should, as insecure mongodb installs are a honeypot for hackers). @dceejay

---

<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:** [8 July 2019 15:06 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014/6 "2019-07-08T15:06:53Z")

</div>

looking forwards to your first PR to fix it 🙂 ... thanks!

---

<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:** [8 July 2019 15:22 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014/7 "2019-07-08T15:22:58Z")

</div>

Something to add to my already long to-do list 😛

---

<div class="post-metadata">

**Author:** ![ljavih](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@ljavih](https://discourse.nodered.org/u/ljavih)\
**Post date:** [9 July 2019 18:50 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014/8 "2019-07-09T18:50:18Z")

</div>

I also use this node and I am able to insert data in MongoDB, but I am unable to extract data from the DB using this node. If you have any idea of how I could do this will be really helpful. Thanks for your help

> [@afelix](#):
>
> ### [node-red-contrib-mongodb3](https://flows.nodered.org/node/node-red-contrib-mongodb3)

---

<div class="post-metadata">

**Author:** ![chloroquine](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@chloroquine](https://discourse.nodered.org/u/chloroquine)\
**Post date:** [28 May 2020 11:15 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014/9 "2020-05-28T11:15:19Z")

</div>

I get a "`failed to connect to server [xxx-shard-00-01-aq7ik.mongodb.net:27017] on first connect`" although I am positive that all the data entered is correct. Any help why this might be?

---

<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:** [28 May 2020 12:04 UTC](https://discourse.nodered.org/t/mongodb-remote-access/13014/10 "2020-05-28T12:04:10Z")

</div>

I see in your address `.mongodb.net`, which I think includes Atlas cloud database. Have you checked in the settings which ip addresses are allowed to access the database remotely?
