Connect to training cluster using WSL2?

Hi, I try to connect to my cluster via WSL2 (Ubuntu 20.04) but I’ve some issues. Note: I’m able to connect through Browser IDE.

We I run :

$ mongo "mongodb+srv://" --username m001-student

It returns :

    DNSProtocolError: Invalid record 3 of DNS answer for "": "Message too long"
    try 'mongo --help' for more information


$ sudo service mongodb status
 * Checking status of database mongodb                       [ OK ]

$ mongo --version
MongoDB shell version v3.6.8
git version: 8e540c0b6db93ce994cc548f000900bdc740f80a
OpenSSL version: OpenSSL 1.1.1f  31 Mar 2020
allocator: tcmalloc
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

Any Help ?

Maybe try upgrading mongo shell to the current version (4.4). Here is the installation guide for Ubuntu.

I had a lot of problem installing following the official procedure

I see, you could try to follow, step by step and ask here or in stackoverflow for guidance.

For now, I would test this string (copy&paste on terminal)

mongo “mongodb://,,” --authenticationDatabase admin --ssl -u m001-student -p m001-mongodb-basics

The reason I test this way, is because srv strings were new in 3.6 so there could be a bug or some trick there.


  • mongo is the binary
  • "mongodb://..." is the address to each server running mongod in replica set configuration. To make sure we connect to primary, I wrote all of them in the string.
  • --auth... is the database we are “registered”
  • --ssl enforces encription when sending the data through the cloud.
  • the rest are user parameters

By the way, ubgxb is your real “password” here. So maybe next time just hide/blur it or replace it by xxxxx.

(I don’t know if you can pass just one and --replSet or something. Couldn’t find that. Not very important anyways.)

Good luck :slight_smile:

Is not the password, it is the cluster name.

The password is given by the -p parameter.

@steevej-1495 Hi. Yes, I meant that everyone knows user and password for the course, so better to keep the string (cluster id) hidden. Sorry for the bad idea of choosing “password”.

Hello everyone!

Here are the steps I took to connect to MongoDB Atlas using WSL2.

All disclaimers flapping in the breeze, including:

"Your Mileage Might Vary!"

First and foremost, I did not bother trying to use the old mongo shell, instead, I downloaded the latest mongosh beta, since I figured I might have better luck with the newest improvements since compatibility with WSL2 was my primary concern.

From the Linux terminal within WSL2, begin with these customary snippets,

  sudo apt-get update
  sudo apt-get upgrade

Now we are ready to download and install mongosh. It took me three simple steps totaling about 10 minutes time.

NOTE: For any command containing a package version number, double-check that the version you are installing is correct; else, edit the snippet accordingly before running it.

1. From the root directory, acquire the software with this command.


2. Extract the files and build the executable by running these two commands.

  tar -zxvf mongosh-0.7.7-linux.tgz
  chmod +x mongosh

3. Finally, establish the symbiotic link to your PATH. First, enter the directory containing the mongosh binaries by running cd bin. And now run this one last snippet.

  sudo ln -s mongosh /usr/local/bin/

Awesome! You can test for a successful install by running ./mongosh in this same directory. You should receive a connection message such as this.

❯ ./mongosh
  Current Mongosh Log ID: 6*******************************c
  Connecting to:    mongodb://

Note: The linking may not work in every situation, it didn’t seem to link completely in my case, but nevertheless, if you follow the rest of the instructions you can still connect to Atlas from WSL2.

Now to connect to the training cluster, go to MongoDB Atlas and get the connection string for the regular mongo shell. Leave the shell version at the default (4.4) and copy the string.

The only difference now is you will always need to cd into the mongosh bin directory, and the command you will call at the start of the string will be ./mongosh instead of just mongo.

So in the end, your connection string and the resulting output should resemble this.

❯ cd bin
❯ ./mongosh "mongodb+srv://sandbox.*****<dbname>" --<username>
Enter password: *******************Current Mongosh Log ID: 6*****************************0
Connecting to:    mongodb+srv://sandbox.*****************
Using MongoDB:      4.4.3
Using Mongosh Beta: 0.7.7
Enterprise atlas-14g1ud-shard-0 [primary]>

Best of luck, and cheers!