This article provides a guide for how to connect MongoDB with MongoDB Compass.
How to Connect MongoDB with MongoDB Compass
To connect MongoDB with MongoDB Compass, follow the steps provided:
Configuring a MongoDB to allow remote connection (bindIP)
Note: Please make sure your mongodb service is running and if firewall is installed in your server please make sure you have allowed the 27017 port on the firewall.
Now you need to make changes in /etc/mongod.conf to allow remote connection.
To allow remote connections, you must edit the MongoDB configuration file /etc/mongod.conf in configuration file look for the bindIp parameter and make sure it is set to either 0.0.0.0 (to allow all IP addresses) or the specific IP address of your server.
For example:-
Here we set bindIp: 127.0.0.1, 2.2.2.2 please add IP address of the server on which you’ve installed MongoDB here we have added dummy ip 2.2.2.2.
If you want to allow all ipv4 and ipv6 Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses.
Now restart MongoDB service
Now we can connect MongoDB with MongoDB Compass
Open MongoDB Compass and click on new connection add IP of your server and click on the Authentication option because the server was secured with authentication enabled you need to enter your administrative MongoDB user’s username, the password.
After selecting this you need to select Authentication and then select Username/Password and add administrative MongoDB user’s Username and password.
Administrative MongoDB user password are store at /var/webuzo/mongodb.conf
In the Authentication Database (optional) field you need to add your custom authentication database.
Now click on connect.
Once the connection is succeeds it will show the list of all the databases.
Conclusion
You now know how to connect MongoDB with MongoDB Compass.