Install MongoDb from HomeBrew
brew install mongodb
Create the default data folder and change permission
sudo mkdir -p /data/db/
Start MongoDb service
brew services start mongodb
Setup authentication
Go to the console
mongo
use admin // create root db.createUser( { user: "root", pwd: "a-password", roles: [ "root" ] } ) // create admin user db.createUser( { user: "admin", pwd: "a-password", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } ) // verify the username and the password db.auth("admin", "a-password")
Create a database user
use admin db.createUser( { user: "dbUser", pwd: "a-password", roles: [{ role: "readWrite", db: "dbUser" }] } ) // verify the username and the password db.auth("dbUser", "a-password")
Adding following in
/usr/local/etc/mongod.conf
security: authorization: enabled
Restart MongoDB
brew services restart mongodb