install and run mongodb on macOS as a non-root user

Optional keyboard
Photo by Jess Bailey / Unsplash

Installing and running mongodb on a mac is very easy with homebrew:

brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb-community

It runs on localhost as a non-root user. You can verify that mongodb is running by searching for mongod in your running processes and by checking for the logs:

ps aux | grep -v grep | grep mongod
tail /usr/local/var/log/mongodb/mongo.log

Use mongo command to start a mongo shell to the running instance. CTRL-D to exit the mongo shell.

The default data directory is /usr/local/var/mongodb which is created when mongodb is installed. The path is set by dbPath in /usr/local/etc/mongod.conf.

This is the default configuration on my mac:

  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
  dbPath: /usr/local/var/mongodb

Hope this helps!

Show Comments