I posted Connect To MongoDB on a Vagrant box from the host on Wednesday, 6 August, 2014

Connect To MongoDB on a Vagrant box from the host
Post vagrant mongodb

Connect To MongoDB on a Vagrant box from the host

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.

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Use Ubuntu 14.04 64 bit
  config.vm.box = "ubuntu/trusty64"

  # Install system requirements
  config.vm.provision "shell", path: "bootstrap/system.sh"

  # Configure guest services to be accessible on host
  config.vm.network "forwarded_port", guest: 3000, host: 3000
  config.vm.network "forwarded_port", guest: 27017, host: 27017
end

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

/etc/mongod.conf
# Listen to local interface only. Comment out to listen on all interfaces.
# bind_ip = 127.0.0.1

Restart the mongod service.

$ sudo service mongod restart

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

Indieweb Social

Did you mention this somewhere? I'd love it if you sent me the link!

disclaimer about timing

Mentions are sent to webmention.io. I fetch the latest mentions when building the site, so I may not see your feedback right away. Especially if my site's broken, which is often the case.

Public replies and mentions might be shared on the site, but I try to do a little quality check first.

Site Links