Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: 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?

like image 558
Darius Avatar asked Dec 24 '17 06:12

Darius


People also ask

Why is MongoDB not connecting to Atlas?

Check that you are using the correct username and password for your database user, and that you are connecting to the correct database deployment. Check that you are specifying the correct authSource database in your connection string.

How do you connect mongo shell to MongoDB?

Connect to MongoDB database Then type mongo command to run the shell. Now you are in the Mongo shell. If you want, you can run the mongo and mongod without the command prompt. To do this, go to the installation location and double click on the mongod and mongo applications.


1 Answers

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

like image 64
grigson Avatar answered Sep 18 '22 03:09

grigson