Tuesday, September 15, 2020

Allow remotely mongodb connection

  No comments

In this tutorial, I will teach you how to make a remote Mongodb connection on the Google Cloud Platform


1. Edit mongod.conf

vim /etc/mongod.conf

2. Change bindIP to 0.0.0.0 or add your mongo host IP

         bindIp: 0.0.0.0

or

bindIp: 127.0.0.1 <your mongodb host IP> 

3. Save and restart mongod

sudo systemctl restart mongod

sudo systemctl status mongod

4. After that, go to your Google Cloud Platform console.  and type

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

and the result is 

Creating firewall...⠹Created [https://www.googleapis.com/compute/v1/projects/trastid/global/firewalls/allow-mongodb].Creating firewall...done.NAME NETWORK DIRECTION PRIORITY ALLOW DENY DISABLED

allow-mongodb default INGRESS 1000 tcp:27017 False

Now you can remote you mongodb with mongodb client, try this command on your terminal to test connection.

mongo admin -u <mongo user> -p <mongo password> --host <your mongo host IP> --port 27017  

 change the tag <text> with your configuration

No comments :

Post a Comment