2

I built a Node.js RestAPI that communicates with a MongoDB. I've deployed this into a host machine. Everything is working, I can use my application and communicate with the RestAPI that writes data into the MongoDB database.

However, I'm trying to get the MongoDB compass on my PC to connect to the MongoDB on the host machine, so I can see the DB in a more user-friendly way, but no matter what I try, I can't get compass to connect with the DB on the host machine.

Mongod is running on 127.0.0.1:27017 on the host machine but accepts external requests. The server has a public IP address, which is in use in the application and works, however, no matter what hostname I try it always says MongoDB isn't running on provided host and port. The host machine is running Ubuntu 16.04.

Can anyone please tell me what are the parameters I need to fill on compass in order to get it to connect?

I've read the documentation, but to no avail.

Thank you!

1 Answer 1

4

If you would like to connect to your MongoDB from difference machine, I think maybe some reasons make this happen:

  1. Do you have make sure Port 27017 is already open for remote access on your Ubuntu firewall setting (UFW)? If no, You can try ufw allow 27017. But I don't really recommend this way for security reason; You can do Port forwarding by iptable.

  2. Do you have turn on Remote Access in your MongoDB configuration? Check This Out

Sign up to request clarification or add additional context in comments.

8 Comments

From the link you gave, I take it I have to check my machine IP and add it do the bindIP in mongod.conf on the server machine. Is that it?
@DiogoMelo That's right. You have to add your client IP into your mongod.conf file. And don't forget to open your PORT 27017 on the firewall setting.
So I did ipconfig on my client machine, got the IPV4 address, added it to the bindIP on mongod.confand tried to connect and still the same error! On the hostname what should I put?
@DiogoMelo well, I have no idea what your ip is. Let's figure out that first, Is the server and client in the same network? If yes, you have to use internal ip address to access your MongoDB server. If no, you have to make sure your router setting that port haven't been block by router. Otherwise, just put your server ip address in the hostname field.
Something is serioulsy wrong, as I have just commented the bindIP line and I still can't connect using the host machine public IP
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.