Automatically power up MongoDB service

If you leverage technology like Node.js in building applications that have to process a high volume of short messages needing low latency, then you might have had to start up MongoDB service. Additionally, itโ€™s exceptionally frustrating when you have to dedicate a tab to it in the terminal knowing you wonโ€™t touch it. I thought there should be a way to run the service from startup item in Mac OS X.

Fortunately, I found a workaround of how I can automate the process when I power up my Mac. Here is how you can do it:

If vim is your default editor, you can do something like this:

sudo vim /Library/LaunchDaemons/org.mongo.mongod.plist

If you donโ€™t sudo into the root directory, it is likely going to output an error and not create the new file. You should enter your password if prompted to do so.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>Label</key>
 <string>org.mongo.mongod</string>
 <key>RunAtLoad</key>
 <true/>
 <key>ProgramArguments</key>
 <array>
  <string>/usr/local/bin/mongod</string>
  <string>--dbpath</string>
  <string>/data/db/</string>
  <string>--logpath</string>
  <string>/var/log/mongodb.log</string>
 </array>
</dict>
</plist>
sudo touch /var/log/mongodb.log
sudo mkdir /data/db
sudo chown root:wheel /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl start org.mongo.mongod

There you have it! You donโ€™t have to worry about running MongoDB service; you can power up your Mac and start working.

Keep on, keeping on! โœŒ๐Ÿฝ

๐Ÿ˜Ž