How to fix connection problems when nothing seems to work - mongodb

I am trying to connect to my atlas cluster from the mongoshell within the windows terminal. The connection string is correctly written and I made sure that the clusters version (4.0.10) and the shell version (4.0.10) are the same. I have also made sure that my ip address is whitelisted and for testing purposes I have added "0.0.0.0/0" as well. Still it doesn't let me connect.
I have tried creating a new database, change user, create new users, change user permissions, changing ip whitelist, using different connection strings, turning off windows firewall, but still, the same error persists.
MongoDB shell version v4.0.10
Enter password:
connecting to: mongodb://charmsdb-shard-00-02-5s81x.mongodb.net.:27017,charmsdb-shard-00-01-5s81x.mongodb.net.:27017,charmsdb-shard-00-00-5s81x.mongodb.net.:27017/test?authSource=admin&gssapiServiceName=mongodb&replicaSet=CharmsDB-shard-0&ssl=true
2019-07-09T12:42:04.136+0200 I NETWORK [js] Starting new replica set monitor for CharmsDB-shard-0/charmsdb-shard-00-02-5s81x.mongodb.net.:27017,charmsdb-shard-00-01-5s81x.mongodb.net.:27017,charmsdb-shard-00-00-5s81x.mongodb.net.:27017
2019-07-09T12:42:04.256+0200 W NETWORK [js] Unable to reach primary for set CharmsDB-shard-0
2019-07-09T12:42:04.256+0200 I NETWORK [js] Cannot reach any nodes for set CharmsDB-shard-0. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
I expect an established network connection but it doesn't let me connect to any.

The problem might be in Window's firewall. MongoDB uses port nr. 27017 so to make it work it has to be opened.
Also if u use Atlas, you can connect through their connection string. https://www.mongodb.com/

Related

can't connect mongo atlas into mongodb compass, shell and Go app

i think this question been asked many times, but i've had this issue also last year and another last year, i resolved it to use VPN provider like nordvpn and tunnelBear. my issue here my company has own VPN which to connect to some internal apps, but i cant connect with multi VPN, my company VPN not resolved the issue to connect Mongo Atlas into Compass, after i install NordVPN in my Linux Fedora, it was solve, but i can't open another internal app if i dont connect with my company VPN. so i tried connect my company VPN while my NordVPN connected as well, but it doesnt work. i need to turn off my private VPN to connect my company VPN. this is really confusing for me if keep to turn off and on my private VPN and Company VPN for my work.
wha i have tried to fix this issues but always failed
change DNS on my fedora /etc/resolv.conf into nameserver 0.0.0.0 or nameserver 8.8.8.8;
change net.bindIp on /etc/mongod.conf into 0.0.0.0 and my ip;
listed ip public in Mongo Atlas 0.0.0.0;
error on mongo compass after paste the URI:
querySrv ENODATA _mongodb._tcp.companyNameHere.ycex0.mongodb.net
error in mongo shell
MongoDB shell version v4.4.3
exception: Failed to look up service "_mongodb._tcp.companyNameHere.ycex0.mongodb.net": Success
exiting with code 1
error in Go app:
panic: error parsing uri: lookup _mongodb._tcp.companyNameHere.ycex0.mongodb.net on XXX.XXX.1.1:53: no such host
those ways not work in my Fedora, i cant connect Mongo Atlas URI in Compass, Go App and Shell as well,
is that any another way ?
my os is: Fedora 33
Try using the standard connection string , as SRV strings sometimes not resolvable by some of the images.
The standard connection string can be obtained in the Atlas UI for the version 3.4 earlier

Unable to connect to mongodb replicaset Google Compute Engine

I have created a 3 node replicaSet for mongodb on google compute engine, for the testing purpose i have added 0.0.0.0/0 for the firewall rule and I'm able to connect to individual node from anywhere and all the instances work without any issue! but the problem is when i tried to connect to the replicaset, using the following command
mongo "mongodb://username:password#public-ip-1:27017,public-ip-2:27017,public-ip-3:27017/production?replicaSet=rs0"
When I'm trying this code another instance on the same project, it work's without any issue
When I try from a different project instance or my local instance, it is throwing error as follow
2020-08-22T14:36:40.579+0530 I NETWORK [thread1] getaddrinfo("mongodb-1-servers-vm-0") failed: nodename nor servname provided, or not known
2020-08-22T14:36:40.582+0530 I NETWORK [thread1] getaddrinfo("mongodb-1-servers-vm-1") failed: nodename nor servname provided, or not known
2020-08-22T14:36:40.582+0530 W NETWORK [thread1] Unable to reach primary for set rs0
and from these instance I'm able to connect to individual nodes separately, as
mongo "mongodb://username:passsword#public-ip-1:27017/production"
mongo "mongodb://username:passsword#public-ip-2:27017/production"
mongo "mongodb://username:passsword#public-ip-3:27017/production"
What could be the problem ?
The second question is, on the firewall these is an option to add app engine service account? so if i disable the 0.0.0.0/0 public access and add this rule, can i connect from my app engine to these instance ?
When connecting to a replica set, the client uses a server discovery process. The basic steps are:
connect to the first host in the connection string
if that fails try the second
once a connection is established, run commands such isMaster to:
discover the names of all of the replica set members
discover which node is currently primary
close the initial connection
connect to every member of the replica set using the hostname and port discovered in step 2
What this means is that the host name returned from rs.conf() or rs.status() must be resolvable by every client that you want to be able to directly connect to the replica set.
From the error message, it looks like the nodes were added to the replica set using short names. If you add the short name for each node to the hosts file on the machine you are connection from, it should work.
Alternately, rebuild the replica set using publicly resolvable hostnames in the rs.initiate and rs.add commands.

Connect to EC2 via MongoDB Compass Community

I have an EC2 instance (Ubuntu 14). I've defined port 27017 in its security group to be accessed from anywhere.
I'm trying to connect from my PC (Windows 10) to the EC2 instance, but getting the following error:
MongoDB not running on the provided host and port
which is not true since I've made sure that MongoDB is running.
These were the settings I specified:
I've also tried to use SSH (which is also defined in the sercurity group and works well through terminal), but got the following error:
Error creating SSH Tunnel: (SSH) Channel open failure: Connection
refused
These were the settings I specified:
Alon,
Checkpoints
See if there is a need to change the bind_ip variable at the /etc/mongodb.conf file.
By default, it is locked to localhost.
Try setting the value to 0.0.0.0 or assign the IP that will be able to connect the DB to it.
Port is allowed in security group attached to EC2 (You mentioned its done)
Not using private IP to connect (I guess, you are using the right one as you connected through terminal)
Rare case, OS firewall
I guess point 1 should do the trick. Rest points for future reference
[Update 1]
Doc link for bindIp
https://docs.mongodb.com/manual/reference/configuration-options/#net-options
I am putting this as an answer although it is meant as a comment to the answer by raevilman above but I do not have the necessary reputation to post comments yet.
If you set the bind_ip variable to 0.0.0.0 as mentioned, MongoDB accepts connections from all IP addresses. This might be a security risk if you do not use access control.
On the other hand, if I am not wrong, the idea of a SSH tunnel is for that, in this case MongoDB, the entering connection comes from localhost so no change in the configuration should be necessary.
That said, I came here because I could not connect either. I got the error 'Error creating SSH Tunnel: Timed out while waiting for forwardOut'.
In my case the solution was to put 'localhost' in the hostname field at the top instead of the host IP.

Connect to Robomongo in a network proxy

I had some connections on Robomongo that worked well, because network didn't have any type of restriction. Now, in the company, network is very restricted and they gave us a Network proxy and some specific IP's, but now, robomongo doesn't allow me to connect to any database, but local.
How can I configure robomongo with this parameters they gave us?
This is the message I get
Cannot connect to the MongoDB at c100.candidate.10.mongolayer.com:10101.
Error: Network is unreachable

Google Cloud Mongo DB: External IP not connecting

I have created a ready to go MongoDB server on Google Cloud using the default parameters. Everything is working fine between them (there is communication and I can add DBs and collections). However, I can't connect to MongoDB on any external machine.
I created the firewall rules in GCP allowing all the connections ("0.0.0.0./0") on the port 27017.
I am running the command:
giuseppe#ubuntu:~$ mongo --host rs0/104.154.xx.xxx,173.255.xxx.xxx,104.197.xxx.xxx
giuseppe#ubuntu:~$ mongo --host rs0/104.154.xxx.xxx:27017,173.255.xxx.xxx:27017,104.197.xxx.xxx:27017
I'm getting the same error on both of them. I don't know how to resolve this issue.
connecting to: rs0/104.154.41.xxx,173.255.xxx.xxx,104.197.22.xxx:27017/test
2015-03-18T19:47:33.770-0500 starting new replica set monitor for replica set rs0 with seeds 104.154.41.xxx:27017,104.197.22.1xx:27017,xx.255.114.xxx:27017
2015-03-18T19:47:33.770-0500 [ReplicaSetMonitorWatcher] starting
2015-03-18T19:47:34.119-0500 changing hosts to rs0/mongo-db-jff3:27017,mongo-db-vnc4:27017 from rs0/104.154.41.246:27017,1xx.197.22.xxx:27017,173.255.1xx.xx:27017
2015-03-18T19:47:34.493-0500 getaddrinfo("mongo-db-vnc4") failed: Name or service not known
2015-03-18T19:47:34.511-0500 getaddrinfo("mongo-db-jff3") failed: Name or service not known
2015-03-18T19:47:34.512-0500 Error: connect failed to replica set rs0/104.154.xxx.xxx:27017,173.2xx.xxx.68:27017,104.197.22.xxx:27017 at src/mongo/shell/mongo.js:148
EDIT:
Here are my firewall settings.
Did you
configure the firewall rule in Google cloud console
provide a tag in your firewall rule
tag your instance with the same tag as the firewall rule
?
I explained how to open a port to the outside world in detail over here. Replace with your own port number.
I belive the issue here is that the ReplicaSetMonitorWatcher is changing hosts to rs0/mongo-db-jff3:27017, where mongo-db-jff3 is not reachable from your network. You need to configure the hosts in the replica set to something that you can reach (static IP or URL).
https://docs.mongodb.com/manual/tutorial/change-hostnames-in-a-replica-set/
Quick example, mongo into your PRIMARY (SECONDARY if you want to do it no downtime):
cfg = rs.conf()
cfg.members[0].host = "mongodb0.example.net:27017"
cfg.members[1].host = "mongodb1.example.net:27017"
rs.reconfig(cfg)