Wednesday 17 May 2017

My node.js application only connects to remote MongoDB server when a local mongod instance is also running

I have used mongodb for many projects, including remote databases but this is the first time I have come across this situation. I am trying to provision a new application server (running node.js) and connect it to the primary mongodb server which is remote. Both are Amazon EC2 instances running in different availability zones, but same region. Again, I have done this before without issue.

After many hours of debugging, I've figured out that the new server will only successfully connect to the remote mongodb server (within node.js) if there is also a local mongod instance running. However, if I shut down the local mongod instance and try running the application, I get Error: connect ECONNREFUSED. I have also tested the connection using telnet and in the mongo shell, both work fine whether or not a local mongod instance is running.

I have tested this in a clean node.js project to make sure it's nothing crazy happening with my code and it exhibits the same behavior. For now, I can move forward and just keep the local mongod instance running even though it serves no purpose, but has anyone else seen this issue before? Thanks in advance.



via Josh Liptzin

No comments:

Post a Comment