05 April 2012

Start/Stop MongoDB Using These Aliases



Just a quick note on working with MongoDB on Linux/Unix.

Recently I needed some ready-made commands to start and stop MongoDB that I could just copy/paste and go, so I created the following aliases for my Bash profile that did the trick. I use these for developing with MongoDB on a MacBook Pro exactly the same way that I make use of aliases for PostgreSQL and MySQL. These are mainly notes for myself for posterity but I'm hopeful that they may also help someone else as well:


# Start up MongoDB using a forked process and log appending
alias mongostart='/var/mongodb/bin/mongod --fork --dbpath /var/mongodb/data/db --logpath /var/mongodb/log/mongodb.log --logappend'

# Shut down MongoDB safely using the soft kill on the PID
alias mongostop="kill -2 `ps aux | grep [m]ongo* | awk '{ print $2 }'`"


Put these in your ~/.bash_profile or ~/.profile, reload the profile and away you go. Obviously you will need to adjust the paths to suit your own environment.

1 comment: