Chapter 0 - test connecting mongo to atlas cluster

At 2.16 min of the Lecture - Atlas requirement , it asks us to test mongo to atlas cluster. when the run the given command after launching mongo.exe ,

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/aggregations?replicaSet=Cluster0-shard-0” --authenticationDatabase admin --ssl -u m121 -p aggregations --norc

I get this error -
uncaught exception: SyntaxError: unexpected token: string literal :
@(shell):1:6

Unable to attempt labs because of this, can someone pls help. Also the video seems to be very old as the sites referred have changed.

2 Likes

You should not launch mongo.exe
Just run the command mongo “your connect string” from your command prompt(os prompt)

Since you already connected to mongo and trying to connect/using mongo again it is giving syntax error

1 Like

Thanks for your prompt reply. I am using Win 10, if I directly give the cmd as suggested it says -

‘mongo’ is not recognized as an internal or external command,
operable program or batch file.

Pls guide.

It is a path problem
Did you update mongodb/bin into PATH?
Alternately you can cd to mongodb/bin directory and run the command

2 Likes

Worked now. Thanks. This tiny instruction may be included in the notes in the chapter :slight_smile:

Nikky_S, could you please let me know the command that was updated in PATH

PATH is a system variable
You have to add full path of your mongodb bin directory to this
What is your os?
Windows or Unix
Search our forum threads.You will get steps to update PATH

I am using Windows.
Updated the PATH , and I am getting below error , when using “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/aggregations?replicaSet=Cluster0-shard-0” --authenticationDatabase admin --ssl -u m121 -p aggregations --norc” connection staing
“‘mongo’ is not recognized as an internal or external command,
operable program or batch file.”

May be your path updates not got saved
You can verify by running path command at your cmd prompt
Can you see mongodb/bin in the output?

1 Like

You need to go to environment variables settings in the control panel and add Path for Mongo. Also to run the command make sure you are in the mondo db directory in your command prompt

1 Like

Got it now. Thanks a lot @Ramachandra_Tummala :blush:

Could someone please provide a connection string that works with Compass? I tried the following but getting the error “No AuthProvider for DEFAULT defined.”

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/aggregations?replicaSet=Cluster0-shard-0

Try this

mongodb://m121:aggregations@cluster0-shard-00-00-jxeqq.mongodb.net:27017/aggregations?authSource=admin&replicaSet=Cluster0-shard-0&readPreference=primaryPreferred&appname=MongoDB%20Compass&ssl=true

3 Likes

if you installed mongosh than use mongosh instead of mongo in start of the command in the prompt

I was trying to connect to the mongo atlas cluster and after some time it fails. the log shows that no primary was found,

2021-08-23T15:19:07.549+0530 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)
2021-08-23T15:19:07.812+0530 I NETWORK [thread1] Detected bad connection created at 1629712146732946 microSec, clearing pool for cluster0-shard-00-02-jxeqq.mongodb.net:27017 of 0 connections
2021-08-23T15:19:07.813+0530 I NETWORK [thread1] Dropping all pooled connections to cluster0-shard-00-02-jxeqq.mongodb.net:27017(with timeout of 5 seconds)
2021-08-23T15:19:07.813+0530 I NETWORK [thread1] Ending connection to host cluster0-shard-00-02-jxeqq.mongodb.net:27017(with timeout of 5 seconds) due to bad connection status; 0 connections to that host remain open
2021-08-23T15:19:07.813+0530 W NETWORK [thread1] No primary detected for set Cluster0-shard-0
2021-08-23T15:19:07.813+0530 E QUERY [thread1] Error: connect failed to replica set 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 :
connect@src/mongo/shell/mongo.js:223:14
@(connect):1:6

exception: connect failed

What is your shell version?