Skip to content

Instantly share code, notes, and snippets.

@echo-dave
Last active October 23, 2019 11:55
Show Gist options
  • Save echo-dave/47aaa9a12ff470053145cab6364d2cb5 to your computer and use it in GitHub Desktop.
Save echo-dave/47aaa9a12ff470053145cab6364d2cb5 to your computer and use it in GitHub Desktop.
MongoDB Standalone Install Mac OS Catalina

Mongodb mac standalone install:

Mongodb community download

move extracted folder and alias (like mysql):

mv ~/Downloads/mongodb-macos-x86_64-4.2.1 /usr/local/
ln -s mongodb-macos-x86_64-4.2.1 mongodb

cd into new mongo bin directory and link into path like homebrews

sudo nano /etc/paths
add
/usr/local/mongodb/bin

make data directory and set owner / perms, make log dir with sudo

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

run mongod as daemon with config file

mongod --fork -f /etc/mongod.conf
shutdown with
kill -2 <mongo pid>
get pid with
ps -ax | grep -i mongo

Baisc config contents

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

To run as service (daemon)

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>

Load the plist into launchd to run at startup

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment