Skip to main content

Mongodb on macOS

Jose CerrejonLess than 1 minuteDeveloperDeveloper

Mongodb on macOS


I've never used MongoDB, but I started a new Node.js course using this NoSQL DB and I'm going to write a few words about how to install it on macOS.

Easy peasy with Homebrewopen in new window.

brew install mongo
brew services start mongo # or stop, restart,...

Now you can set up new users typing mongo in a Terminal. When you get the prompt, type:

use admin
db.createUser({ user: "mongo", pwd: "mongo", roles: [{ role: "root", db: "admin" }] })
# if you already have a database (for example, homstead), add a new user with:
use homestead
db.createUser({ user: "homestead", pwd: "secret", roles: [{ role: "dbOwner", db: "homestead" }] }) 

You have a great multiplatform GUI called MongoDB Compass to access your databases. It's free and you can download it at www.mongodb.comopen in new window.