How I can start mongodb automatically?

I'm doing like here is described

http://hunterford.me/mongodb-startup-item/

but my file called different and path is here ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist. and mongo is starting well, but after system restart i have go through two last command again

sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl start org.mongo.mongod

Solution 1:

If you have to use sudo to load it, the plist file may be owned by root. Launchd will only automatically load agents that you own from ~/Library/LaunchAgents, where it will load agents owned by root from /Library/LaunchAgents.

You can do ls -l ~/Library/LaunchAgents to view the ownership of the plist. If you actually want it to run under your user account, you can change it's ownership:

sudo chown `whoami` ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

However, if you need to run mongod as root, you should leave the plist in /Library/LaunchDaemons