Install MongoDB
1. Update Homebrew’s package database.
brew update
brew install mongodb
2. Install MongoDB
# stable
brew install mongodb
# or dev
brew install mongodb --devel
Run MongoDB
1. Create the data directory.
mkdir -p /data/db
# or
sudo mkdir -p /data/db
2. Set permissions for the data directory.
# try run
mongod
# if error
sudo chown -R $USER /data/db
3. Run MongoDB.
# <mongod path> --dbpath <path to data directory>
mongod
# or
mongod --dbpath /data/db
4. Verify that MongoDB has started successfully.
# MongoDB has started successfully by checking the process output for the following line
[initandlisten] waiting for connections on port 27017
5. Begin using MongoDB.
# mongo shell
mongo
Ref :
MongoDB Doc