Running MongoDB
On some platforms—such as Ubuntu—the package manager will automatically start the mongod daemon for you, and ensure it starts on boot also. On others, such as Mac OS X, you must write your own script to start it, and manually integrate with launchd so that it starts on system boot.
Note that before you can start MongoDB, its data and log directories must exist.
If you wish to have MongoDB start automatically on boot on Windows, 10gen have a document describing how to set this up at http://www.mongodb.org/display/DOCS/Windows+Service
To have MongoDB start automatically on boot under Mac OS X, first
you will need a plist file. Save the following (changing db and log paths
appropriately) to /Library/LaunchDaemons/org.mongodb.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>RunAtLoad</key>
<true/>
<key>Label</key>
<string>org.mongo.mongod</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mongodb/bin/mongod</string>
<string>--dbpath</string>
<string>/usr/local/mongodb/data/</string>
<string>--logpath</string>
<string>/usr/local/mongodb/log/mongodb.log</string>
</array>
</dict>
</plist>Next run the following commands to activate the startup script with launchd:
sudo launchctl load /Library/LaunchDaemons/org.mongodb.mongod.plist sudo launchctl start org.mongodb.mongod
A quick way to test whether there is a MongoDB instance ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access