Last Updated: February 25, 2016
·
1.088K
· carlosescri

Start/Stop MongoDB in local development environment: detaching from terminal the easy way

I use a very simple approach to start and stop mongo without having a terminal opened for it. To make this work I use aliases (this trick only works in *NIX operative systems). Edit your shell's profile and add these alias (in my case this was .bash_profile):

alias start_mongo="mongod run --config /usr/local/etc/mongod.conf --fork --rest"
alias stop_mongo='mongo admin --eval "db.shutdownServer()"'

Reload your profile or open a new terminal. Now you can type start_mongo and stop_mongo to manage your MongoDB local instance.

The path to the mongo config file may vary depending on your OS.