0

I'm trying to follow this tutorial [1], but MongoDB is refusing connections, as error messages says:

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

Node-RED is running from a docker container, and MongoDB is on the host machine

MongoDB service is running properly, and when I type on browser "localhost:27017", appears "It looks like you are trying to access MongoDB over HTTP on the native driver port" message.

How to make, so, MongoDB accepts connections from NodeRED?

[1] https://www.youtube.com/watch?v=f5o4tIz2Zzc

  • Are you _sure_ that the MongoDB service is running properly? If you can't connect, that suggests that it isn't. – Vince Bowdren Apr 24 '17 at 18:58
  • Yes, it is. I've verified via "htop" and "service", and in both cases it's shown that mongodb is running. – Inácio Medeiros Apr 25 '17 at 02:34
  • The mongodb server logs will probably tell you what's up; have you checked them yet? – Vince Bowdren Apr 25 '17 at 08:04
  • Logs say nothing about it, it's like no connection were made. – Inácio Medeiros Apr 26 '17 at 02:51
  • Detail: Node-RED is running from a docker container, and MongoDB is on the host machine. – Inácio Medeiros Apr 26 '17 at 02:56
  • That is not just a detail, that is the heart of the entire problem! You can't connect to a host machine service, from within a container, using the address "localhost" because that is the address of the container, not the host. – Vince Bowdren Apr 26 '17 at 08:42
  • Possible duplicate of [From inside of a Docker container, how do I connect to the localhost of the machine?](http://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – Vince Bowdren Apr 26 '17 at 08:43
  • That worked! I've set --net=host to docker container, and connections to MongoDB were possible. Thank you so much, Vince! – Inácio Medeiros May 01 '17 at 03:02

0 Answers0