Connection error : MongoDB Shell to MongoDB Atlas

2,959 views
Skip to first unread message

RAJ SINGH

unread,
May 26, 2018, 9:44:13 PM5/26/18
to mongodb-user
Hi,

I have been trying to connect mongoDB shell from my local system to below cluster used for mongoDB  class on EDX portal :


Getting below error every time :

2018-05-26T19:22:05.396+0530 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:6  

I am able to connect  successfully with Atlas cluster via mongoDB compass from my system but shell connection has failed. 

MongoDB version installed : 3.6
MongoDB Shell version  : 3.6.5

Tried searching but was not able to resolve problem. Please could you help .

Thanks
raj

RAJ SINGH

unread,
May 28, 2018, 4:17:49 AM5/28/18
to mongodb-user
Hi,

Please can anyone help me out.

thanks
Raj

Kevin Adistambha

unread,
May 29, 2018, 8:58:38 PM5/29/18
to mongodb-user

Hi Raj

2018-05-26T19:22:05.396+0530 E QUERY [thread1] SyntaxError: missing ; before statement @(shell):1:6

Could you run the mongo shell command using the --norc parameter?

If you can connect without any issue, you may want to take a look at your ~/.mongorc.js (in Unix systems) file and check it for errors — a missing semicolon from the error message. See the mongorc.js page for more information.

If you still having errors, please post the complete shell output you’re seeing from mongo invocation up to the error.

Best regards
Kevin

RAJ SINGH

unread,
May 30, 2018, 11:15:05 AM5/30/18
to mongodb-user
Hi Kevin,

Thanks for responding mate. I did try what you mentioned but that did not help me. Please find attached snapshots for your reference.

I have mongoDB 3.6.5 2008R2Plus Enterprise (64 Bit) and MongoDB Compass installed on my system as suggested in MongoDB basics class. Interesting part is i am able to connect to both Altas clusters [ one cluster shared in mongoDB class and second one which i created online via mongoDB portal ] via compass installed on my system.

thanks
Raj
errorSnapshot.jpg
shell and MongoDB version.jpg

Kevin Adistambha

unread,
May 31, 2018, 8:28:13 PM5/31/18
to mongodb-user

Hi Raj

The mongo shell is a Javascript interpreter. Trying to type mongo <server address> <additional parameters> inside the shell is a syntax error (it is not a Javascript statement or any supported command). This is the source of the SyntaxError: missing ; before statement output.

There are more details in the mongo shell page regarding the shell.

To connect to your Atlas instance, you should type at the command prompt:

C:\Users\user> mongo "mongodb://<your Atlas deployment address>" --ssl --authenticationDatabase admin --username <your username> --password <PASSWORD>

I would also recommend you to peruse the free courses at the MongoDB University, e.g. M001 which is a thorough introduction to MongoDB. The next session will start at 5 June.

Best regards
Kevin

Yogesh Irmal

unread,
Dec 10, 2018, 4:11:48 PM12/10/18
to mongodb-user
Hello Raj,

Did you get any solution?
I am facing the same issue, not able to find any help on google.

Best Regards,
Yogesh Irmal

Josip Subašić

unread,
Jan 20, 2019, 5:54:13 PM1/20/19
to mongodb-user
Helloo,

I tried Kevin 's solution by typing Atlas deployment like this: 
And nothing special happen to that. But then I typed exit command from mongo db, copy/paste original code from MongoDB University 
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

and I get what was on the instructor's screen. I exit again from test cluster and renamed it to 100YWeather and result was this last line in cmd: 
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

I hope that this somehow helps.

Best regards

Mahesh Jamdade

unread,
Jan 23, 2019, 11:26:17 PM1/23/19
to mongodb-user
for those who are facing the issue I recommend following the docs I tried it and I was able to connect to the mongo atlas from the cmd .
  • I actually added the mongo shell to my environment variable
  • made sure I have a user added to the cluster with proper privileges
  • make sure you have your IP whitelisted 
  • open cmd and check mongo version by typing "mongo --version"
  • choose the appropriate connection string according to your version and the paste and execute in cmd
this should get you connected to the database
Reply all
Reply to author
Forward
0 new messages