I want to have access to my MongoDB database remotely. for example: with the MongoDB compass but I receive this error: connection <monitor> to <my_server_ip>:27017 closed
my MongoDB database is installed on a ubuntu VPS and the ubuntu version is 20.04 and I want to connect to my database with my windows computer which has MongoDB compass.
I followed along with this tutorial to configure remote access for MongoDB: https://www.digitalocean.com/community/tutorials/how-to-configure-remote-access-for-mongodb-on-ubuntu-20-04
I think there must be something wrong with the firewall or IP access.
I'm new to Linux and I've tried everything that I could but I couldn't figure it out
- at first, my
/etc/mongod.conf
was like this:
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1, 136.243.244.202
the ip 136.243.244.202
is the ip address of the Linux VPS which the MongoDB is running on
- then, I changed the bindIp to something like the code below and restarted the MongoDB with
sudo systemctl restart mongod
but again it didn't work:
bindIp: 0.0.0.0
- I also tried to open port
27017
withsudo ufw allow 27017
in addition, when I run sudo ufw status
, the result is like this:
root@moonfo:~# sudo ufw status
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx Full ALLOW Anywhere
27017 ALLOW Anywhere
22 ALLOW Anywhere
27017/tcp ALLOW Anywhere
27017 ALLOW 136.243.244.202
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
27017 (v6) ALLOW Anywhere (v6)
22 (v6) ALLOW Anywhere (v6)
27017/tcp (v6) ALLOW Anywhere (v6)
and when I run sudo lsof -i | grep mongo
to see which port the MongoDB is listening to, the output is the response below:
mongod 69866 mongodb 10u IPv4 1324230 0t0 TCP *:27017 (LISTEN)
mongod 69866 mongodb 46u IPv4 1393764 0t0 TCP kvm.jupiter.7ho.st:27017->5.122.78.214:15066 (ESTABLISHED)
I'm new to Linux and everything that I did, couldn't solve my problem.
I just want to be connected to my MongoDB database from any computer, it doesn't matter which computer it is. and the connection url that I use to be connected in MongoDB compass is something like this:
mongodb://<db_username>:<db_username_password>@136.243.244.202:27017/admin
as I mentioned, the ip address of 136.243.244.202
is the ip address of the server which my database is running on.
and the other thing is that my database is active and running on the VPS and I can connect to it locally but I can't connect to it remotely