Skip to content

Instantly share code, notes, and snippets.

@garily
Last active February 20, 2020 05:21
Show Gist options
  • Save garily/3194e20e1036fdc4425afbaac1d59b9f to your computer and use it in GitHub Desktop.
Save garily/3194e20e1036fdc4425afbaac1d59b9f to your computer and use it in GitHub Desktop.
Installing mongoDB on macOS with Homebrew
# install mongodb-community using homebrew
$ brew tap mongodb/brew
$ brew install mongodb-community

# back up default config file
$ cp /usr/local/etc/mongod.conf{,.bak}

# to start the service at system startup
$ brew services start mongodb-community

# OR start the service manually
$ mongod --config /usr/local/etc/mongod.conf --fork

# connect to mongoDB
$ mongo

# inside mongoDB-cli
> db.disableFreeMonitoring()
> use admin
> db.createUser({ user: "admin", pwd: passwordPrompt(), roles: [ { role: "dbAdminAnyDatabase", db: "admin" } ] })
> db.adminCommand({ shutdown: 1 })
> exit

# if using brew services
# enable authentication in mongod.conf
$ echo -e "security:\n  authorization: enabled" >> /usr/local/etc/mongod.conf

# restart mongod service
$ brew services restart mongodb-community

# OR if using command line
$ mongod --config /usr/local/etc/mongod.conf --fork --auth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment