There are two different ways for installing MongoDB on your Mac either manually or through Homebrew. We will be looking at the steps required to install MongoDB through Homebrew. If you don’t have brew already installed on your Mac, you can install it by simply running the below command on your Terminal.
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Update Homebrew’s package database
$ brew update
Install the MongoDB binaries
$ brew install mongodb
Build MongoDB from Source with TLS/SSL Support
$ brew install mongodb --with-openssl
Install the Latest Development Release of MongoDB
$ brew install mongodb --devel
1. Create db directory
$ sudo mkdir -p /data/db
2. To keep the MongoDB always running even after restarts use the below commands.
//Start mongod main process on session start: $ ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents //Start MongoDB now, in background, and keep it running $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
3. Just type mongo on your Terminal and start using the MongoDB
Some of the command required to change the default configurations
//Select manually the data directory $ mongod --dbpath //Select manually the log file $ mongod --logpath //Select manually the configguration file $ mongod --config