Skip to content

Instantly share code, notes, and snippets.

@cvan
Last active October 4, 2023 19:13
Show Gist options
  • Save cvan/1d38741d32ad818c9b4db8d751075748 to your computer and use it in GitHub Desktop.
Save cvan/1d38741d32ad818c9b4db8d751075748 to your computer and use it in GitHub Desktop.
launch mongodb's mongod daemon on macOS boot

Edit the plist file

Add the following XML content to the plist file. Replace /usr/local/bin/mongod with the correct path to your MongoDB executable if it's different. You may also need to adjust other settings like the data directory or log paths.

Launch Terminal. Create this new file:

nano ~/Library/LaunchAgents/com.mongodb.mongod.plist

Paste the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.mongodb.mongod</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/mongod</string>
        <string>--config</string>
        <string>/usr/local/etc/mongod.conf</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

Save and exit

Save the file in nano by pressing Ctrl + O, then press Enter, and exit nano by pressing Ctrl + X.

Load the LaunchAgent

To load the LaunchAgent and start MongoDB, use the launchctl command:

launchctl load ~/Library/LaunchAgents/com.mongodb.mongod.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment