Cant connect to new replica set master / Unable to reach primary for set

Capturemgdb Capturemgdb2

I am able to connect
vagrant@m103:/shared$ mongo mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/video?replicaSet=Cluster0-shard-0 --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics
MongoDB shell version v3.6.9

2019-02-07T12:31:24.242+0000 I NETWORK [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to cluster0-shard-00-02-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-02-jxeqq.mongodb.net:27017 with a 5 second timeout)
MongoDB server version: 3.6.10
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db
video

1 Like

Unable to replicate the issue. Try again.

Make sure you have internet connection running.

Kanika

1 Like

Hello @everyone. thanks for the help.
I tried again without replica set and it connects me to secondary. am not sure if this is the right place as i know i am suppose to be on primary. With the replicaSet perimeter, it fails.

with replica set


mongo “mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?replicaSet=Cluster0-shard-0” --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics

without replica set


mongo “mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test” --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics

I am using code from >>> https://university.mongodb.com/mercury/M001/2019_January_2/chapter/Chapter_2_The_MongoDB_Query_Language_Atlas/lesson/595aae2236942e83e9a361b9/tab/595aae2236942e83e9a361b8

I am unable to replicate the issue. :frowning:

I successfully connected using the first string with replicaSet with 4.0.5 version.

Let me share the issue with the team and I will get back to you.

Kanika

1 Like

I am having the same issue. I copied the standard connection string directly into the cmd for windows and it just went on showing [unable to reach primary for “clustername”] and [cannot reach any nodes for “clustername”] . In the end it showed connection failed, need urgent help with this issue as the labs due date is tomorrow.

1 Like

Until we get response from above :slight_smile:

you can establish connection to secondary if you remove the replicaSet flag but you cant do anything from the training with this connection sadly; i was lucky to get a connection to primary after reconnecting a couple of times but after i lost that connection, i couldn’t connect to primary anymore. you can also gain access using compass but i doubt if there is a way to load the data required in the videos for some of the tasks into the db using compas.

In the end, i had to open the data file and manually search through them to get the right answers to the labs :disappointed_relieved:

There is also another option of using one of the programming languages that mongodb supports to make a connection and perform queries… node maybe. but this depends on if you already know those languages enough to do something in them real fast.

I am getting a similar error… unable to reach primary.

C:\Users\TP_Mike>mongo “mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?replicaSet=Cluster0-shard-0” --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics
MongoDB shell version v4.0.6
connecting to: mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?authSource=admin&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0
2019-02-11T18:39:55.182-0700 I NETWORK [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017
2019-02-11T18:39:55.513-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:39:55.514-0700 I NETWORK [js] 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.
2019-02-11T18:39:56.434-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:39:56.435-0700 I NETWORK [js] 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.
2019-02-11T18:39:57.395-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:39:57.396-0700 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 3 checks in a row.
2019-02-11T18:39:58.337-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:39:58.337-0700 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 4 checks in a row.
2019-02-11T18:39:59.172-0700 I NETWORK [js] Successfully connected to cluster0-shard-00-01-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-01-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-02-11T18:39:59.545-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:39:59.695-0700 I NETWORK [js] Marking host cluster0-shard-00-01-jxeqq.mongodb.net:27017 as failed :: caused by :: SocketException: can’t authenticate against replica set node cluster0-shard-00-01-jxeqq.mongodb.net:27017 :: caused by :: socket exception [CONNECT_ERROR] server [cluster0-shard-00-01-jxeqq.mongodb.net:27017] connection pool error: couldn’t connect to server cluster0-shard-00-01-jxeqq.mongodb.net:27017, connection attempt failed: SocketException: The token supplied to the function is invalid
2019-02-11T18:40:00.051-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:00.189-0700 I NETWORK [js] Marking host cluster0-shard-00-01-jxeqq.mongodb.net:27017 as failed :: caused by :: SocketException: can’t authenticate against replica set node cluster0-shard-00-01-jxeqq.mongodb.net:27017 :: caused by :: socket exception [CONNECT_ERROR] server [cluster0-shard-00-01-jxeqq.mongodb.net:27017] connection pool error: couldn’t connect to server cluster0-shard-00-01-jxeqq.mongodb.net:27017, connection attempt failed: SocketException: The token supplied to the function is invalid
2019-02-11T18:40:00.557-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:00.695-0700 I NETWORK [js] Marking host cluster0-shard-00-01-jxeqq.mongodb.net:27017 as failed :: caused by :: SocketException: can’t authenticate against replica set node cluster0-shard-00-01-jxeqq.mongodb.net:27017 :: caused by :: socket exception [CONNECT_ERROR] server [cluster0-shard-00-01-jxeqq.mongodb.net:27017] connection pool error: couldn’t connect to server cluster0-shard-00-01-jxeqq.mongodb.net:27017, connection attempt failed: SocketException: The token supplied to the function is invalid
2019-02-11T18:40:01.046-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:01.326-0700 I NETWORK [js] Successfully connected to cluster0-shard-00-01-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-01-jxeqq.mongodb.net:27017 with a 0 second timeout)
2019-02-11T18:40:02.043-0700 I NETWORK [js] Successfully connected to cluster0-shard-00-02-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-02-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-02-11T18:40:02.111-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:02.898-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:03.677-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:04.455-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:05.233-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:06.009-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:06.784-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:07.562-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:08.344-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:09.135-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:09.916-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:10.695-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:11.470-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:12.243-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:13.046-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:13.843-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:14.619-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:15.425-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:16.217-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:40:16.218-0700 E QUERY [js] Error: Could not find host matching read preference { mode: “primary”, tags: [ {} ] } for set Cluster0-shard-0 :
connect@src/mongo/shell/mongo.js:343:13
@(connect):1:6
exception: connect failed

C:\Users\TP_Mike>mongo “mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?replicaSet=Cluster0-shard-0” --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics
MongoDB shell version v4.0.6
connecting to: mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?authSource=admin&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0
2019-02-11T18:46:05.805-0700 I NETWORK [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017
2019-02-11T18:46:06.156-0700 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-11T18:46:06.156-0700 I NETWORK [js] 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.
2019-02-11T18:46:06.966-0700 I NETWORK [js] Successfully connected to cluster0-shard-00-00-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-00-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-02-11T18:46:07.182-0700 I NETWORK [js] Marking host cluster0-shard-00-00-jxeqq.mongodb.net:27017 as failed :: caused by :: Location40659: can’t connect to new replica set master [cluster0-shard-00-00-jxeqq.mongodb.net:27017], err: couldn’t connect to server cluster0-shard-00-00-jxeqq.mongodb.net:27017, connection attempt failed: SocketException: The token supplied to the function is invalid
2019-02-11T18:46:08.180-0700 I NETWORK [js] Marking host cluster0-shard-00-00-jxeqq.mongodb.net:27017 as failed :: caused by :: Location40659: can’t connect to new replica set master [cluster0-shard-00-00-jxeqq.mongodb.net:27017], err: couldn’t connect to server cluster0-shard-00-00-jxeqq.mongodb.net:27017, connection attempt failed: SocketException: The token supplied to the function is invalid
2019-02-11T18:46:09.170-0700 I NETWORK [js] Marking host cluster0-shard-00-00-jxeqq.mongodb.net:27017 as failed :: caused by :: Location40659: can’t connect to new replica set master [cluster0-shard-00-00-jxeqq.mongodb.net:27017], err: couldn’t connect to server cluster0-shard-00-00-jxeqq.mongodb.net:27017, connection attempt failed: SocketException: The token supplied to the function is invalid
2019-02-11T18:46:09.593-0700 I NETWORK [js] Successfully connected to cluster0-shard-00-01-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-01-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-02-11T18:46:09.799-0700 I NETWORK [js] Marking host cluster0-shard-00-01-jxeqq.mongodb.net:27017 as failed :: caused by :: SocketException: can’t authenticate against replica set node cluster0-shard-00-01-jxeqq.mongodb.net:27017 :: caused by :: socket exception [CONNECT_ERROR] server [cluster0-shard-00-01-jxeqq.mongodb.net:27017] connection pool error: couldn’t connect to server cluster0-shard-00-01-jxeqq.mongodb.net:27017, connection attempt failed: SocketException: The token supplied to the function is invalid
2019-02-11T18:46:09.800-0700 E QUERY [js] Error: can’t authenticate against replica set node cluster0-shard-00-01-jxeqq.mongodb.net:27017 :: caused by :: socket exception [CONNECT_ERROR] server [cluster0-shard-00-01-jxeqq.mongodb.net:27017] connection pool error: couldn’t connect to server cluster0-shard-00-01-jxeqq.mongodb.net:27017, connection attempt failed: SocketException: The token supplied to the function is invalid :
connect@src/mongo/shell/mongo.js:343:13
@(connect):1:6
exception: connect failed

@zinoadidi I was able to fix the issue via this post… Connecting to atlas through shell

Basically the posted link in the curriculum is wrong. Remove the “test” from the end of the connection string and instead input “100YWeatherSmall”

Scratch that… I was able to connect once, then never again. I even created my personal cluster and was not able to connect to that either.
The solution was to install the older 3.6.10 release of MongoDB, reset the ENV Path variable to reflect the 3.6 folder, and then close CMD, reopen, and connect. Everything is working good now.

1 Like

This right here is what i was trying to explain earlier. i connected once and went to sleep lol.
came back in the morning and couldn’t connect again :frowning:

Thanks for the fix @mthiel79 I hope everyone who has same issue can find this and complete their labs in time.

I think your answer is correct because i started having this issue when i upgraded my mongo installations to the latest at the beginning of the course.

Good luck!

@Kanika maybe there is a problem with the latest release and or connection string?

@Ritik_90659 any luck with your labs? did you try the recent answer yet

I am unable to reproduce the issue, so I cannot confirm the same.

If you can help me getting more information like screenshots of the error, making sure you are using 4.0.6 (current version - Enterprise) and not any development release.

Then, I may be able to debug the issue.

Kanika

image

Same issue unable to connect via shell but can connect via Compass

I get similar error "Unable to reach primary for set Cluster0-shard-0; Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. "

C:\Users\deept>mongo “mongodb://cluster0-shard-00-00-rtgye.mongodb.net:27017,cluster0-shard-00-01-rtgye.mongodb.net:27017,cluster0-shard-00-02-rtgye.mongodb.net:27017/100YWeatherSmall?replicaSet=Cluster0-shard-0” --ssl --authenticationDatabase admin --username m001-student --password m001-mongodb-basics
MongoDB shell version v4.0.5
connecting to: mongodb://cluster0-shard-00-00-rtgye.mongodb.net:27017,cluster0-shard-00-01-rtgye.mongodb.net:27017,cluster0-shard-00-02-rtgye.mongodb.net:27017/100YWeatherSmall?authSource=admin&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0
2019-02-12T16:40:15.732+0530 I NETWORK [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-rtgye.mongodb.net:27017,cluster0-shard-00-01-rtgye.mongodb.net:27017,cluster0-shard-00-02-rtgye.mongodb.net:27017
2019-02-12T16:40:17.112+0530 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-02-12T16:40:17.113+0530 I NETWORK [ReplicaSetMonitor-TaskExecutor] 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.
2019-02-12T16:40:19.557+0530 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-12T16:40:19.557+0530 I NETWORK [js] 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.
2019-02-12T16:40:22.021+0530 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-12T16:40:22.021+0530 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 3 checks in a row.
2019-02-12T16:40:24.506+0530 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-12T16:40:24.507+0530 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 4 checks in a row.
2019-02-12T16:40:26.999+0530 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-12T16:40:26.999+0530 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 5 checks in a row.
2019-02-12T16:40:29.484+0530 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-12T16:40:29.484+0530 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 6 checks in a row.
2019-02-12T16:40:32.029+0530 W NETWORK [js] Unable to reach primary for set Cluster0-shard-0
2019-02-12T16:40:32.029+0530 I NETWORK [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 7 checks in a row.
2019-02-12T16:40:32.033+0530 E QUERY [js] Error: connect failed to replica set Cluster0-shard-0/cluster0-shard-00-00-rtgye.mongodb.net:27017,cluster0-shard-00-01-rtgye.mongodb.net:27017,cluster0-shard-00-02-rtgye.mongodb.net:27017 :
connect@src/mongo/shell/mongo.js:328:13
@(connect):1:6
exception: connect failed

I was connected to my cluster until yesterday. Today i am unable to connect and i get this error. i tried the above solutions but none works.I Can neither connect via shell nor compass. i am able to connect to the work cluster that we used for our initial session.

Have connected to the Class Atlas DB but get same error for my own sandbox

Have a different error now connecting to my sandbox

connection pool error: network error while attempting to run command ‘isMaster’ on host

using the short SRV Connection String

I had same issue for several hours today connecting both class and sandbox clusters

2019-02-12T04:07:12.786+0000 W NETWORK [ReplicaSetMonitor-TaskExecutor-0] Unable to reach primary for set Cluster0-shard-0
2019-02-12T04:08:02.827+0000 I NETWORK [ReplicaSetMonitor-TaskExecutor-0] getaddrinfo(“cluster0-shard-00-00-jxeqq.mongodb.net”) failed: Temporary failure in name resolution

Able to connect now to both

vagrant@m103:~$ mongo mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?replicaSet=Cluster0-shard-0 --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics
MongoDB shell version v3.6.9
connecting to: mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?replicaSet=Cluster0-shard-0
2019-02-12T12:03:25.790+0000 I NETWORK [thread1] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017
2019-02-12T12:03:27.049+0000 I NETWORK [thread1] Successfully connected to cluster0-shard-00-02-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-02-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-02-12T12:03:27.416+0000 I NETWORK [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to cluster0-shard-00-01-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-01-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-02-12T12:03:28.498+0000 I NETWORK [thread1] Successfully connected to cluster0-shard-00-00-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-00-jxeqq.mongodb.net:27017 with a 5 second timeout)
Implicit session: session { “id” : UUID(“75eadb46-58af-4c0c-9a6d-ed7061cc2a99”) }
MongoDB server version: 3.6.10
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db
test
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show dbs
100YWeatherSmall 0.117GB
admin 0.000GB
aggregations 0.067GB
citibike 0.361GB
city 0.002GB
config 0.000GB
coursera-agg 0.083GB
local 1.076GB
mflix 0.292GB
results 0.000GB
ships 0.001GB
video 0.404GB
MongoDB Enterprise Cluster0-shard-0:PRIMARY> use 100YWeatherSmall
switched to db 100YWeatherSmall
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show collections
data
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

1 Like

Interesting… seems to be a network issue then.

What did you do differently?

Nothing different
I used the same command which failed earlier in the night
Did not even restart shell or compass

Yes likely N/W issue

Please make sure you are not running the mongo command while connected to mongo shell
You have to run it at os prompt
For those who already connected to mongo shell simply quit() and retry