Mongo shell is not working

Hi all,

I am trying to work through exercises in Mongodb university. One of the issues I came across is that when I use mongosh it always gives me an Syntax error, please see below:

mongod --port 27000
Uncaught:
SyntaxError: Unexpected token, expected “;” (1:9)

1 | mongod --port 27000

Does anyone know how to fix it? The customer support is not helping at all except for suggesting to post a question on this forum.

I have not seen your post on the MongoDB University. What is your user name at MongoDB University?

MongoDB University courses are based on the legacy mongo shell. The new mongosh is not covered in the university course.

Most likely, you are trying to run mongod while already connected to one of the mongo or mongosh shells.

@Timur_Akhmadulin Hey, If you are doing some exercise from MongoDB University you must have seen the complete connection string in the previous lecture(s). By adding the complete string you can connect your system to their server.
For example the connection string for basic course is as followed:

mongo “mongodb+srv://cluster0-jxeqq.mongodb.net/test” --username m001-student --password m001-mongodb-basics

If you still have some confusing you can share the course link so that we can send you the connection string (if you are connecting your system to their server)

HI @Nabeel_Raza,

Thank you for such prompt reply.

I am doing M103 the first lab. Below is the link

https://university.mongodb.com/mercury/M103/2020_August_4/chapter/Chapter_1_The_Mongod/lesson/5e54545fad8aed99fcd86276/problem

below is what I try to do.
mongod --port 27000

my user name is timurta@hotmail.com

M103 has a specific forum at the university.

Please post a screenshot of the issue overthere.

@Timur_Akhmadulin make sure that you have set the MongoDB environmental variable in your system. if you are trying it from local system (using command line)

The error message

is typical to the mongo shell javascript interpreter.

Most likely scenario, he did a first mongo -nodb or mongosh --nodb and then try to start mongod at the mongo or mongosh prompt. He has to exit the current javascript interpreter and return to the bash interpreter from the in browser IDE.

It is specific to the M103 course and it is best to have this discussion over there.

HI,

Thank you for the suggestion. I already tried. Before I set up environmental variable the mognosh would just disappear after I try to start it. Not it does not, but the errors are the same.

Uncaught:
SyntaxError: Unexpected token, expected “;” (1:9)

1 | mongod --port27000
| ^
2 |

HI,

Not sure I understood the solution. Would you please elaborate more? Thank you.

In your latest post there is no space between port and 27000

What steevejSteeve Juneau mentioned was you might have been at mongo prompt already and when you try mongod command it will fail with syntax error

So exit from mongo prompt and run the command from os prompt(sh#4.4)

I hope you are running the commands for the lab in IDE

All good now, thanks a lot to all of you. It was really a combination of all your suggestions.