Hi Guys, Welcome to Proto Coders Point. In this article will learn How to config mongodb to access globally that is mongodb remote connection, so that we can preform CRUD operation into mongo database by using Mongodb compass GUI tool by using server ip.
Basically, mongodb allow access from anywhere by using IP address & port in DB compass.
MongoDB remote connection – Globally access
1. Add global bindIp in mongod.config
To make database globally accessable, you need to change in mongod.conf file bindIP to 0.0.0.0 or your server IP.
1. Open mongod.conf file
sudo vim /etc/mongod.conf
press shift + i (key)
to go into INSERT mode and change bindIp to 0.0.0.0
.
net: port: 27017 bindIp: 0.0.0.0
press ESC (key)
to come out from INSERT mode, then press :wq
to save & exit mongod.conf.
2. AWS server side – give access permission TCP mongoDB port
In AWS dashboard navigate to
EC2 > Instance > click on instance ID > Security > Security groups > Edit inBound rules > Add rule
Here select type > select custom TCP & port range enter 27017( i.e. mongodb port ).
then same the rules
3. Connect to Database using MongoDB compass
Open db compass, connect > new Connection > Paste your connection string
mongodb://<HOST IP>:27017/
Example:
mongodb://18.191.199.130:27017/
Therefore, you have successfully, changed your database to be accessed globally using host IP.