Now, mf you want to connect to the mongodb databse from another machine or like using it in a backend service. What is the connection string ?
Technically mongodb://localhost:2717,localhost:2718,localhost:2719/?replicaSet=myReplicaSet
But as your are trying to connect from another machine, you need the ip address or domain configured for that machine.
- Connection string :
mongodb://146.190.90.245:2717,146.190.90.245:2718,146.190.90.245:2719/?replicaSet=myReplicaSet
- Use a mongodb client like "MongoDB Compass"
- Failed or connection timeout!
Can you check which connection port are open for the machine ?
-
nmap 146.190.90.245
Starting Nmap 7.80 ( https://nmap.org ) at 2023-06-14 12:40 UTC Nmap scan report for neogenacademy.com (146.190.90.245) Host is up (0.0000060s latency). rDNS record for 146.190.90.245: ubuntu-s-4vcpu-8gb-intel-sgp1-01 Not shown: 995 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 3000/tcp open ppp 5000/tcp open upnp 5432/tcp filtered postgresql Nmap done: 1 IP address (1 host up) scanned in 1.49 seconds
- Now access to the mongodb server and check firewall ( you should use firewall)
- `sudo ufw status`
Status: active
To Action From
OpenSSH ALLOW Anywhere
3000/tcp ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
3000/tcp (v6) ALLOW Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)
In mycase, necessary ports (2717, 2718, and 2719) are not open for incoming connections.
- add them :)
- `sudo ufw allow 2717`
- `sudo ufw allow 2718`
- `sudo ufw allow 2719`
- check : `sudo ufw status`
Status: active
To Action From
OpenSSH ALLOW Anywhere
3000/tcp ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
2717 ALLOW Anywhere
2718 ALLOW Anywhere
2719 ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
3000/tcp (v6) ALLOW Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)
2717 (v6) ALLOW Anywhere (v6)
2718 (v6) ALLOW Anywhere (v6)
2719 (v6) ALLOW Anywhere (v6)
use
rs.addArb()
for arbitary