$ brew tap mongodb/brew
$ brew install mongodb-community@5.0.6
/*TO START*/
brew services start mongo-community
/*TO STOP*/
brew services stop mongo-community
// updated 2021
$ brew tap mongodb/brew
$ brew install mongodb-community@4.4
brew services start mongodb-community@4.2
#Step 3 to run as a service
Install brew using the -- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew tap mongodb/brew
brew install mongodb-community@5.0
brew install mongodb-community@4.2
#Step 2
//Starts Mongdb server @ mongodb://127.0.0.1:27017/
brew services start mongodb-community@4.2
mongod --config /usr/local/etc/mongod.conf --fork
ps aux | grep -v grep | grep mongod
mongo
command to activate mongodb through a terminal
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
brew install mongodb-community@5.0
// updated 2022
// watch this video it will help you download and configure mongodb
// locally so that mongod command will work
// I did not made the video nor I would benefit but after spending more
// than one hour installing it and not make it work this helped me alot
// and finally made it work
// Use this for macos latest versions
// https://www.youtube.com/watch?v=4crXgQZG4W8
//be sure you have GNU's GCC:
brew install gcc
brew tap mongodb/brew
brew tap mongodb/brew
brew install mongodb-community@[version number]