Cannot connect to cluster using mongoshell

(MongoDB shell version v4.0.10)
I follow instruction, enter below command:
mongo mongodb+srv://m220student:m220password@mflix-xxxx.mongodb.net/test
It failed. Part of the error message is:
*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.
I do whitelist using “ALLOW ACCESS FROM ANYWHERE”
If I remove the last piece “/test”, I can connect, but the prompt is:
MongoDB Enterprise mflix-shard-0:SECONDARY>
Why SECONDARY, not PRIMARY?

Hi @tien_nguyen,

You need to replace this with the cluster command from cloud.mongodb.com.
Steps to do :

  1. Login to cloud.mongodb.com
  2. Select your cluster.
  3. Click Connect
  4. Connect with Mongo Shell
  5. Copy the command from there and then try again.

Let me know if that helps.

Kanika

Thanks, Kanika. Your instructions are exactly the same as in the course. I tried once again and the issue still exists. The command is:
mongo “mongodb+srv://mflix-xxxx.mongodb.net/test” --username m220student

As said earlier, if I remove the last piece ‘/test’, I can connect, but only to the SECONDARY

Hi @tien_nguyen,

Oh! Can you please share the screenshot of your command line / terminal ?

Kanika

Remove last piece ‘/test’

I have similar kind of problemCluster_connection_err

Hi @Sreekumar_85793,

I am able to connect using the below command:

  mongo mongodb+srv://m220student:m220password@mflix-ctbar.mongodb.net

Please make sure your firewall is not enabled. And your network should allow request from this cluster.

Kanika

@tien_nguyen
I think the problem is your user is not a cluster Admin. The readme asked us to create one user with only readAndWrite permission.

Try logging into your Atlas Cluster from the web, create an Atlas Admin user then connect through shell with that credential.

I got the same warning when I try to connect using the connect string for this course. Still I don’t know why I got the PRIMARY. Let’s wait for our support engineer to diagnose the issue.

Primary is correct
You always connect to primary
Please ignore those warning messages
Yes as you said user should have more privileges(R/W) to avoid seeing those warning essages
tien_nguyen
I tried your commands both with and without test
Able to connect fine
C:\Users\ramrt>mongo “mongodb+srv://mflix-1yust.mongodb.net” --username m220student --password m220password
MongoDB shell version v4.0.5
connecting to: mongodb://mflix-shard-00-00-1yust.mongodb.net.:27017,mflix-shard-00-01-1yust.mongodb.net.:27017,mflix-shard-00-02-1yust.mongodb.net.:27017/?authSource=admin&gssapiServiceName=mongodb&replicaSet=mflix-shard-0&ssl=true
MongoDB server version: 4.0.10
Error while trying to show server startup warnings: user is not allowed to do action [getLog] on [admin.]
MongoDB Enterprise mflix-shard-0:PRIMARY> db
test
MongoDB Enterprise mflix-shard-0:PRIMARY>

Solved. It was issue with port 27017.Thank you

My issue is due to the DNS. Credit is due to Quang_80634 who helped me out in another topic.