Google Cloud Platform - Can't connect to mongodb

这一生的挚爱 提交于 2019-12-01 16:59:54

As the other answers in this thread suggest, mongod daemon is listening on TCP port 27017. Therefore, you will need to add a firewall rule on Compute Engine firewall for this port and protocol. This can be done using Google Cloud console or using gcloud command tool:

gcloud compute firewall-rules create allow-mongodb --allow tcp:27017

It is recommended to use target tag with the firewall rule and use this target tag to specify what VM instances the firewall rule should be applied to.

Adding the port in the firewall is not enough. By default the host bind to 127.0.0.1 which needs to be changed to 0.0.0.0 Make changes in the file sudo nano /etc/mongod.conf inside the instance Look for the term bindIp change it to 0.0.0.0 and restart mongodb You will be able to connect to the mongo db now

Click on the Http or Https checkbox to activate the external ip address so u can use it to access the database

On the Mongodb project you should open firewall for port 27017.

MongoDB used ports are listed at:
http://docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/

Regards,
Paolo

Splaktar

This answer explains how to set the firewall rule for port 27017.

Another issue that could cause this is running your mongodb in a separate network and having your other instances on the default network (or vice versa).

I ran into this and after getting both instances on the same network, it was able to connect to the mongo instance by name.

Here's an example of how to set the network for a managed VM in your app.yaml:

network:
  instance_tag: https-server
  name: my-node-network
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!