Unable to connect to MongoDB from a VPN - mongodb

My Mongo database is hosted on MongoDB Atlas cloud server. I am unable to connect to the server when I am on VPN(company network). When I disconnect from the VPN and try, it works fine. I have tried through multiple options, from Mongo Compass, command line, through code snippet. It's the same problem.
I have whitelisted my public IP address on the Mongo Atlas server but still unable to connect.
On Mongo Compass I get the following error :
Connection URI : mongodb+srv://<username>:<password>#<hostname>
Error : connect ECONNREFUSED 52.42.97.161:27017
From command line :
Command : mongo "mongodb://<hostname>:27017" --ssl --authenticationDatabase admin --username <username> --password <password>
Error :
W NETWORK [thread1] Failed to connect to 54.148.205.233:27017 after 5000ms milliseconds, giving up.
W NETWORK [ReplicaSetMonitor-TaskExecutor-0] Failed to connect to 34.211.199.170:27017 after 5000ms milliseco ds, giving up.
W NETWORK [ReplicaSetMonitor-TaskExecutor-0] Failed to connect to 52.42.97.161:27017 after 5000ms millisecond , giving up.
W NETWORK [ReplicaSetMonitor-TaskExecutor-0] No primary detected for set Field-shard-0
I NETWORK [ReplicaSetMonitor-TaskExecutor-0] All nodes for set Field-shard-0 are down. This has happened for checks in a row.
W NETWORK [thread1] Failed to connect to 34.211.199.170:27017 after 5000ms milliseconds, giving up.
W NETWORK [thread1] Failed to connect to 52.42.97.161:27017 after 5000ms milliseconds, giving up.
W NETWORK [thread1] Failed to connect to 54.148.205.233:27017 after 5000ms milliseconds, giving up.
W NETWORK [thread1] No primary detected for set Field-shard-0
I NETWORK [thread1] All nodes for set Field-shard-0 are down. This has happened for 2 checks in a row.
E QUERY [thread1] Error: connect failed to replica set Field-shard-0/field-shard-00-00.xvwf9.mongodb.net:27 17,field-shard-00-01.xvwf9.mongodb.net:27017,field-shard-00-02.xvwf9.mongodb.net:27017 :
connect#src/mongo/shell/mongo.js:237:13 #(connect):1:6 exception: connect failed
Please let me know what I can try to make this work. Thanks!

Related

mongodb exception connection failed

when I'm trying to open mongodb with command prompt I'm getting a error message like
D:\mongo-bd\bin>mongo.exe
MongoDB shell version v3.6.4
connecting to: mongodb://127.0.0.1:27017
2018-04-27T18:50:28.340+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1
:27017 after 5000ms milliseconds, giving up.
2018-04-27T18:50:28.340+0530 E QUERY [thread1] Error: couldn't connect to ser
ver 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
I have tried by running mongo --repair command but still I'm facing this problem.
1 First set up the data directory - google it
2 then run the
{installationDirectory}/MongoDB/Server/{serverVersion}/bin/mongod.exe
to start the service
3 Get into the shell
{installationDirectory}/MongoDB/Server/{serverVersion}/bin/mongo.exe

mongodb installation error connection failed on windows

I have tried all solutions mentioned in below 2 links
Mongodb: Failed to connect to 127.0.0.1:27017, reason: errno:10061
How to start mongo db on windows
But still getting below error
`C:\Program Files (x86)\MongoDB\Server\3.2\bin>mongo MongoDB shell
version: 3.2.18-15-g678cb63 connecting to: test
2018-01-26T16:39:23.926+0530 W NETWORK [thread1] Failed to connect to
127.0.0.1 :27017 after 5000ms milliseconds, giving up. 2018-01-26T16:39:23.927+0530 E QUERY [thread1] Error: couldn't
connect to ser ver 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14 #(connect):1:6
exception: connect failed`
Open onemore terminal as admin and run mongod. After this you can start your app in main terminal.

Cannot connect to mongodb atlas through mongo shell

I've checked other similar posts but none worked for my case.
I upgraded my mongo shell right before connecting to MongoDB Atlas, from which I created a free sandbox database. I used this following for my connection, which was given by atlas.
mongo "mongodb+srv://cluster0-z2lf6.mongodb.net/test" --authenticationDatabase admin --username <user> --password <password>
image of the user of database:
screenshot of the overview of the database:
These are the detail of database:
However, the terminal displays this (I only included about 15 lines, the rest are repetitions.):
MongoDB shell version v3.6.0
connecting to: mongodb+srv://cluster0-z2lf6.mongodb.net/test
2017-12-24T14:39:42.806+0800 I NETWORK [thread1] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-z2lf6.mongodb.net.:27017,cluster0-shard-00-01-z2lf6.mongodb.net.:27017,cluster0-shard-00-02-z2lf6.mongodb.net.:27017
2017-12-24T14:39:42.990+0800 W NETWORK [ReplicaSetMonitor-TaskExecutor-0] Failed to connect to 34.232.245.97:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-24T14:39:42.991+0800 W NETWORK [thread1] Failed to connect to 35.168.27.238:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-24T14:39:43.492+0800 W NETWORK [ReplicaSetMonitor-TaskExecutor-0] Failed to connect to 52.20.90.64:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-24T14:39:43.492+0800 W NETWORK [ReplicaSetMonitor-TaskExecutor-0] Unable to reach primary for set Cluster0-shard-0
2017-12-24T14:39:43.492+0800 I NETWORK [ReplicaSetMonitor-TaskExecutor-0] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
2017-12-24T14:39:43.997+0800 W NETWORK [thread1] Failed to connect to 35.168.27.238:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-24T14:39:44.000+0800 W NETWORK [thread1] Failed to connect to 34.232.245.97:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-24T14:39:44.003+0800 W NETWORK [thread1] Failed to connect to 52.20.90.64:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-24T14:39:44.004+0800 W NETWORK [thread1] Unable to reach primary for set Cluster0-shard-0
2017-12-24T14:39:44.004+0800 I NETWORK [thread1] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 2 checks in a row.
What could be the reason for this connection error?
In my case reason was that provider changed my ip address (I have dynamic ip, behind NAT)
after I've updated ip whitelist, connection was restored
Actually the reason why I couldn't connect is because I had a network restriction from my university's wifi. I was given a test url http://portquiz.net:27017 from MongoDB's support team, I opened it in a browser and I couldn't access it.
I changed to another place with wifi and it worked.
The new atlas ui - please note that for better security you should not use 0.0.0.0/0 nut your own ip address or use available timer to terminate the rule

mongodb replicaset connection error

I am getting connection errors, when I try to connect to my replica set either in PHP code or in the mongo shell.
1. PHP
This is the php code trying to make the connection:
$manager = new MongoDB\Driver\Manager("mongodb://remoteServerIp:27017/".$db."?replicaSet=rs0");
and the connection result is this error:
No suitable servers found (`serverSelectionTryOnce` set):
[connection timeout calling ismaster on '10.10.0.16:27017']
[connection timeout calling ismaster on '10.10.0.17:27017']
[connection timeout calling ismaster on '10.10.0.15:27017']
2. mongo shell
If I try this command to connect in the mongo shell:
shell> mongo -host "rs0/remoteServerIp"
... the result is this error:
MongoDB shell version: 3.2.10 connecting to: rs0/remoteServerIp:27017/test
2016-12-28T02:19:02.216+0000 I NETWORK [thread1] Starting new replica set monitor for rs0/xxx.xxx.xxx.xxx:27017
2016-12-28T02:19:02.216+0000 I NETWORK [ReplicaSetMonitorWatcher] starting
2016-12-28T02:19:07.216+0000 W NETWORK [thread1] Failed to connect to xxx.xxx.xxx.xxx:27017, reason: errno:115 Operation now in progress
2016-12-28T02:19:07.216+0000 W NETWORK [thread1] No primary detected for set rs0
2016-12-28T02:19:12.716+0000 W NETWORK [thread1] Failed to connect to xxx.xxx.xxx.xxx:27017, reason: errno:115 Operation now in progress
2016-12-28T02:19:12.716+0000 W NETWORK [thread1] No primary detected for set rs0
2016-12-28T02:19:18.216+0000 W NETWORK [thread1] Failed to connect to xxx.xxx.xxx.xxx:27017, reason: errno:115 Operation now in progress
2016-12-28T02:19:18.216+0000 W NETWORK [thread1] No primary detected for set rs0
2016-12-28T02:19:18.216+0000 E QUERY [thread1] Error: connect failed to replica set rs0/xxx.xxx.xxx.xxx:27017 : connect#src/mongo/shell/mongo.js:231:14 #(connect):1:6
3. mongo shell (private ip address)
By contrast, this connection attempt succeeds:
shell> mongo -host "rs0/privateip(10.10.0.16)"
How can I connect to mongo server with replicaset ?

Could not connect to mongodb. errno:111 Connection refused

I am using mongodb on ubuntu-16.04 but mongodb give server connection error:
MongoDB shell version: 3.2.9 connecting to: test
2016-09-23T12:01:10.258+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-09-23T12:01:10.286+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : connect#src/mongo/shell/mongo.js:229:14 #(connect):1:6 exception: connect failed
What can I do?
looks like your mongod process is not running on port 27017. Make sure your mongod process is running maybe verify with linux command.
If you start mongod process and even then it's failing to connect with mongo command, it means it's failing to intialize, check out designated mongo log file for the reason