Collecting my attempts to improve at tech, art, and life

Connect To MongoDB on a Vagrant box from the host

Tags: vagrant mongodb tools

Yesterday I finished a little project to set up a reusable Vagrant box for MongoDB and Perl Mojolicious experiments. That project is okay as it is right now, but I would like to get at MongoDB from the host system.

It is not painfully difficult, but it would be easy for me to forget. That is why I made a post out of it.

Adjust the Vagrantfile so that the MongoDB guest port is forwarded to a host port.


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Use Ubuntu 14.04 64 bit = "ubuntu/trusty64"

  # Install system requirements
  config.vm.provision "shell", path: "bootstrap/"
  # Configure guest services to be accessible on host "forwarded_port", guest: 3000, host: 3000 "forwarded_port", guest: 27017, host: 27017

Inside the box, comment out the bind_ip line from /etc/mongod.conf.

# Listen to local interface only. Comment out to listen on all interfaces.
# bind_ip =

Restart the mongod service.

$ sudo service mongod restart

Connect to Mongo from the host using whatever interface you prefer. I have been enjoying Robomongo.

Added to vault 2024-01-15. Updated on 2024-02-01