I use a Mac for development but I don't actually do my development on my Mac. I don't want to pollute my filesystem with a myriad of different programming languages and different versions of those languages. That can lead to instability. I chose to either use Docker containers or VMs within my Mac. This comes with its own problems - sometimes connectivity can be a problem.
I am developing a Go web app on a Ubuntu 16.04 VM which is provisioned using Vagrant and an Ansible playbook. The app is using MongoDB as a document store. It's always useful to have a DB GUI to refer to during development. MySQL and Sequel Pro are a match made in heaven. In MongoDB land, the GUI of choice is Robo 3T (Formally Robomongo). Robo 3T is installed on my Mac (Host machine) - now how do I connect it to my Ubuntu VM (Guest machine)?
We will be using SSH Tunneling to gain access to the guest machine. Navigate to your project's folder on the host machine in a terminal. This is the directory which contains the Vagrantfile. Issue a vagrant ssh-config command. This will give us the information to populate the Robo 3T configuration screens.
Open up Robo 3T and navigate to the SSH tab in Connections. Since we are using SSH tunneling, tick the checkbox at the top left of the form. Now you need to populate the rest of the fields. Perhaps counter-intuitively, the SSH address is always your Host, and therefore 127.0.0.1, and as per the Vagrant configuration posted earlier, the port is 2222. The user name is vagrant and we will be using the private key listed above. You'll note that directories starting with the dot file (hidden files) on a Mac aren't shown by default. So to find the .vagrant directory, you will need the shift-cmd-dot keystroke combination.
Now go to the connection tab. I need a Direct Connection (and not a replica set) for my VM, and again the address should be your Host's 127.0.0.1. The port however is the default port used by MongoDB - 27017. Once this is done you should be in a position to click Test to check everything is ok. Save the configuration and you should now be able to open the connection to MongoDB and see something to my screen at the top of the page.