How to use Mongosh to connect the course's cluster?

I can use Git bash to do so successfully. But every time I use Mongosh, always see errors.

Do not type mongosh by itself.

What ever you cut-n-paste when you are prompted to enter a MongoDB connection string, this is the command you need to enter.

Hi Steeve,

Actually, I tried typing without ‘mongosh’, with/without quotation mark, and with/without flags such as authenticationDatabase, but still get errors, can you share yours?

Plus, when there is an error, mongosh app always exits. I need to find it and open it again, wasting time. Is there any way to keep it open?

Thank you

I found this way works:

But still want to know how to apply the following from the course into mongosh
“mongodb://,,” --authenticationDatabase admin --tls -u m121 -p aggregations

The exact command is in Chapter 0 - Lecture Atlas Requirements.

Start with mongosh rather than mongo.

Still waiting for a solution on how to apply the following command in Mongosh. Please help paste your command. Thank you.

mongosh “mongodb://,,” --authenticationDatabase admin --tls -u m121 -p aggregations

Yes, I did copy and past it from chapter 0, but see the errors as mentioned above.

You apply the command exactly like you posted.

Post a screenshot that shows exactly what you do and the resulting error.

This is the snapshot, the same as I posted at the beginning.

Do you double-click on mongosh.exe to start it?

You should start a terminal, like cmd.exe ou PowerShell and then cut-n-paste the mongosh command.

Hi Steeve,

Yes, I double-click to open the Mongosh.exe
I can successfully use this command to connect in Windows CMD terminal, Git Bash, Git CMD, etc., except

I just don’t know why MongoDB’s own terminal does NOT support it’s command.

1 Like

Hi Doug, I’ve read your reply. If all of you guys recommend using other terminals but not Mongosh.exe, I will do so, too. I’m just curious. As you can see from what I posted 6 days ago, after I modified the connection commanded, I can connect successfully.

The course chapter 0 said:

So I guess it lets students use Mongosh.exe. So Mongosh is embedded into the OS environment, and actually, we access it by Windows terminal, Git CMD… Am I understanding right?

Sorry, I removed my previous message quickly after posting as I was just saying the same thing that Steevej stated, and saw that you had resolved the issue.

mongosh is a command line tool that is to be run from a terminal window (cmd, bash, powershell, etc). On my Mac, if I try to double click on mongosh from finder, it will do one of two things:

  • If I have an instance of MongoDB up and running locally, it will open up a connection to a locally running MongoDB instance (this is the default)
  • If I do not have an instance of MongoDB up and running locally, it will briefly flash my terminal window as it tries to connect and then fails

The mongo tools (mongo, mongosh, mongotop, mongostat, etc) are all meant to be run from a terminal window, and not ran by double clicking on the application from your file manager, although they might work if you have a locally running MongoDB instance. I don’t have a Windows machine handy to test what would happen if trying to start from Windows Explorer, but it was interesting that you screenshot shows that it asked for a connection string. I wonder if you just put in the "mongodb://..." portion if that would have worked or not. You would have needed to convert the command line options to the correct connection string format, so you might not have gotten very far even if you did get connected.

Here is a sample connection string for connecting to MongoDB Atlas from Compass:


Note that the username, password, database to use (test), authentication database (admin) and the tls setting are all part of the connection string.

mongosh is the newer, and recommended, command line access into the database. It has most of the features of the older mongo tool. There are GUIs that can be used as well such as Compass or a number of third party tools. It really depends on what you’re trying to do and what your comfort level with the different tool set is on which is best. For the most part I stick with mongosh, unless I’m dealing with large and complex documents, but then I’m more comfortable in a terminal world.


Thank you so much for your detailed response.

Here is the answer, still report an error.

Following is the only way I found to connect successfully in Mongosh.exe, as you mentioned, modified it based on the syntax of a connection string in Atlas.


You should be able to open git bash (I believe that’s the terminal you stated you were running) and then type in the command similar to the following:

mongosh "mongodb+srv://" --apiVersion 1 --username <username> --password --tls

Note that since I don’t have a string after the --password flag it will prompt me to enter my password. Doing things this way doesn’t make you convert flags to connection string equivalents. Again it all comes down to what you’re most comfortable doing.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.