Connect MongoDB using Compass


Let’s say, you have a MongoDB database server in your private subnet, which means you can’t connect or access it publicly. In this case, you may need to connect to MongoDB database with the SSH tunnel using a Compass.

In this post, we will use MongoDB Compass a Graphical User Interface (GUI) for querying, aggregating, and analyzing our data in MongoDB.

Let’s connect MongoDB database with SSH tunnel using Compass

  1. Download MongoDB compass from this link.
  2. Install MongoDB compass and open it.
  3. Go to Connect menu from top left and click on Connect to
Connect MongoDB using Compass 3 1
  1. Click on Fill in connection fields individually
Connect MongoDB
  1. Hostname:
    • Hostname: The hostname of your MongoDB server. It can be IP of DNS
    • Port: If you haven’t changed you can leave it as default or you can add new one if it is different.
    • Authentication: Choose your authentication type. If it is username and password then select Username / Password
    • Username: Your MongoDB username.
    • Password: Your password
    • Authentication Database: The authentication database for you user
Connect MongoDB database
  1. Click More Options
    • SSH Tunnel and choose Use Identity File
    • SSH Hostname: The public IP. It is kind of Bastion Host IP
    • SSH Tunnel Port: 22
    • SSH Username: SSH Username (If you are using Ubuntu instance of AWS EC2 then it is likely to Ubuntu)
    • SSH Identity File: Click Select a file… and and choose your SSH Key file.
    • SSH Passphrase: Enter your pass if any otherwise you can leave it blank
Connect MongoDB database with SSH
  1. Click the Connect button.
Connect MongoDB database with SSH tunnel using Compass

Now it should be connected successfully.

Congratulations! You are now successfully connected to your MongoDB database with an SSH tunnel.

Notify of
Inline Feedbacks
View all comments