Hey,
Here's the steps to start your MongoDB every time you switch on your Mac machine.
Step1: Save the below contents into /Library/LaunchDaemons/org.mongo.mongod.plist
<?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>/opt/local/bin/mongod</string>
<string>--dbpath</string>
<string>/opt/local/var/db/mongodb</string>
<string>--logpath</string>
<string>/opt/local/var/log/mongodb.log</string>
</array>
</dict>
</plist>
Step2: Create the log file and DB directory
sudo chown root:wheel /Library/LaunchDaemons/org.mongo.mongod.plist
sudo touch /var/log/mongodb.log
sudo mkdir /var/lib/mongodb
sudo mkdir -p /opt/local/var/db/mongodb
Step3: Run the following commands in terminal to load the file into launchctl
sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl start org.mongo.mongod
Thats it! Happy coding!
Here's a useful links : MongoDB-OSX-Launchctl
The chown command refers to wrong path. It should be /Library/LaunchDaemons/org.mongo.mongod.plist not /System/Library/LaunchDaemons/org.mongo.mongod.plist
ReplyDeleteAlso there is no need for
ReplyDeletesudo touch /var/log/mongodb.log
sudo mkdir /var/lib/mongodb
since nothing is being stored there
Please see:
ReplyDeletehttp://iosdeveloperforums.com/f23/mongodb-startup-mac-osx-136.html
IOS FORUMS
ReplyDelete