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 the file in nano by pressing Ctrl + O
, then press Enter
, and exit nano by pressing Ctrl + X
.
To load the LaunchAgent and start MongoDB, use the launchctl
command:
launchctl load ~/Library/LaunchAgents/com.mongodb.mongod.plist