mv ~/Downloads/mongodb-macos-x86_64-4.2.1 /usr/local/
ln -s mongodb-macos-x86_64-4.2.1 mongodb
sudo nano /etc/paths
add
/usr/local/mongodb/bin
sudo mkdir /var/db/db_mongo; chmod 771 /var/db/db_mongo; chown staff /var/db/db_mongo; mkdir /var/log/mongodb ;chmod 777 /var/log/mongodb
mongod --fork -f /etc/mongod.conf
shutdown with
kill -2 <mongo pid>
get pid with
ps -ax | grep -i mongo
sudo nano /etc/mongod.conf
# setup logging
systemLog.path: /var/log/mongodb/mongod.log
systemLog.destination: file
# set data storage
storage.dbPath: /var/db/db_mongo
sudo touch /Library/LaunchDaemons/local.mongod.plist
sudo nano localmongod.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>local.mongod</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mongodb-macos-x86_64-4.2.1/bin/mongod</string>
<string>--config</string>
<string>/etc/mongod.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>HardResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>4096</integer>
</dict>
<key>SoftResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>4096</integer>
</dict>
</dict>
</plist>
sudo launchctl load -w local.mongod.plist
At this point it should be running if you do a ps -ax | grep -i mongo
It's worth noting that for some reason the $PATH in terminal is not the same as what's available to launchctl. It's currently unclear how to fix it so that we can short had the executable path in the plist file.