Unable to connect to MongoDB Cluster

I just created an Atlas Cluster as defined in Chapter 2, Lab 2. Added whitelist entry and the user and still unable to connect. I can connect to the class cluster used in Chapter 1. I have also enoded the password properly for the new cluster.

On the command line, I get authentication error whereas using Compass I get a timeout error as shown below, respectively.

It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.

2020-01-04T18:58:27.312+0500 E  QUERY    [js] Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-01-04T18:58:27.318+0500 F  -        [main] exception: connect failed
2020-01-04T18:58:27.318+0500 E  -        [main] exiting with code 1

I am using Ubuntu 19.10, Mongo v4.2.2, and Compass 1.20.4 stable. I’ll be glad if someone could help me out here.

Thanks.

When I ping ajbozdarcluster0-srzz3.mongodb.net, I get “No address associated with hostname”. I am not sure why I get this error. Probably, this is the reason compass freezes.

It’s weekend. Anyone here? Is everyone off today?

Can you share the connect string you are using?
From where you got that
Not able to ping your hostname
It may be SRV string
Try this

ping ajbozdarcluster0-shard-00-00-srzz3.mongodb.net

Pinging ec2-3-125-150-198.eu-central-1.compute.amazonaws.com [3.125.150.198] with 32 bytes of data:
Reply from 3.125.150.198: bytes=32 time=140ms TTL=52
Reply from 3.125.150.198: bytes=32 time=138ms TTL=52

So modify your connect string using class cluster command.It may work

Yes its weekend so you may get slow response

I got the connect string from here.

ping ajbozdarcluster0-shard-00-00-srzz3.mongodb.net works
Where exactly connect string is located if above is the wrong place?
What is the difference between SRV string and connect string?

I get this error when I try to use Compass if I add shard-00-00 in connect string.

querySrv ENOTFOUND _mongodb._tcp.ajbozdarcluster0-shard-00-00-srzz3.mongodb.net

Using mongo shell, I tried mongo "mongodb+srv://ajbozdarcluster0-shard-00-00-srzz3.mongodb.net/test" --username m001-student and it resulted as below:

DNSHostNotFound: Failed to look up service "_mongodb._tcp.ajbozdarcluster0-shard-00-00-srzz3.mongodb.net": Success

try 'mongo --help' for more information

Like @Ramachandra_37567 requested, please share the full connection string that you used on the command line.

Have you done this?

Also ensure that the username/password is correct. Where did you set this up on your Atlas cluster?

This is the connection string I am using to connect via command line:
mongo "mongodb+srv://ajbozdarcluster0-srzz3.mongodb.net/test" --username m001-student
It prompts me for the password but then declines to connect.

Yes, I have done this as instructed during the lecture. Security --> Network Access --> IP Whitelist.

Username and Password are corrrect and I set them up in Security --> Database Access --> MongoDB Users:

Include the --password in the connection string and try again. And also paste that here too.

Here it is:
mongo “mongodb+srv://ajbozdarcluster0-srzz3.mongodb.net/test” --username m001-student --password m001-mongodb-basics

Below is the result, and now this is new:

MongoDB shell version v4.2.2
2020-01-05T02:12:50.719+0500 F - [main] exception: No digits
2020-01-05T02:12:50.719+0500 E - [main] exiting with code 1

Let me try with URL encoded password again. I did this before using both CLI and Compass.

Here is the update result with encoded password:

mongo "mongodb+srv://ajbozdarcluster0-srzz3.mongodb.net/test"  --username m001-student --password m001%2dmongodb%2dbasics
MongoDB shell version v4.2.2
connecting to: mongodb://ajbozdarcluster0-shard-00-00-srzz3.mongodb.net:27017,ajbozdarcluster0-shard-00-01-srzz3.mongodb.net:27017,ajbozdarcluster0-shard-00-02-srzz3.mongodb.net:27017/test?compressors=disabled&gssapiServiceName=mongodb&ssl=true


*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.


2020-01-05T02:18:04.403+0500 E  QUERY    [js] Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-01-05T02:18:04.405+0500 F  -        [main] exception: connect failed
2020-01-05T02:18:04.405+0500 E  -        [main] exiting with code 1

Am I wrong while encoding the password?

Passwords are string literals, they don’t need to be encoded.

Create a new simple Read-Only user as follows:
username: user
password: password

…wait for it to complete and try connecting again. Let me know when you’ve created the user so that I can try it on my end.

Okay, I am doing this. Please see the screenshot in OP. It talks about encoded passwords. It was not in lecture, though.

Please,
ReadOnlyUser:
user: m001-student-readonly
pass: m001-mongodb-basics

Command outcome:

mongo "mongodb+srv://ajbozdarcluster0-srzz3.mongodb.net/test"  --username m001-student-readonly --password m001-mongodb-basics
MongoDB shell version v4.2.2
connecting to: mongodb://ajbozdarcluster0-shard-00-00-srzz3.mongodb.net:27017,ajbozdarcluster0-shard-00-01-srzz3.mongodb.net:27017,ajbozdarcluster0-shard-00-02-srzz3.mongodb.net:27017/test?compressors=disabled&gssapiServiceName=mongodb&ssl=true


*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.


2020-01-05T02:31:13.030+0500 E  QUERY    [js] Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-01-05T02:31:13.033+0500 F  -        [main] exception: connect failed
2020-01-05T02:31:13.033+0500 E  -        [main] exiting with code 1

Please create a very simple username and password exactly like above. I know it’s not the most secure combination but you will be able to delete it afterwards.

Sure no problem.

I am not sure in which time zone you are at the moment. I am grateful of your help here.

Here is the new user.
username: user
password: mypass12 (Atlas was not allowing me to proceed with a dead simple password). Please accept.

No problem. We’re here to help :wink:

Ok, this works for me. Try on your end.

Glad to know this. And ‘jb’ is common in our IDs. They are my middle and last initials. :handshake:

Tried thrice. Connect Failed, exited with code 1.

This is exactly what I used:
mongo "mongodb+srv://ajbozdarcluster0-srzz3.mongodb.net/test" --username user --password mypass12

:sunglasses: :+1: but it’s actually not my initials