13

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: image of the user of database

screenshot of the overview of the database: screenshot of the overview of the database

These are the detail of 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?

Wan B.
  • 18,367
  • 4
  • 54
  • 71
Darius
  • 441
  • 1
  • 5
  • 13

3 Answers3

13

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

enter image description here

grigson
  • 3,458
  • 29
  • 20
7

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.

Darius
  • 441
  • 1
  • 5
  • 13
  • 1
    http://portquiz.net:27017 is your friend, if the page doesn't load then your port is blocked. – Andrew Nov 14 '19 at 00:12
  • Great advice as amongst other info it shows your outgoing IP. In my case it was different to those ones I've obtained using other methods. After I've added it to the MongoDB.Atlas IP Whitelist everything started working. – Vyacheslav Orlovsky Feb 11 '20 at 17:29
3

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

enter image description here

moshe beeri
  • 2,007
  • 1
  • 17
  • 25