How to Install MongoDB 4.x on MacOS with Homebrew

The following tutorial uses Homebrew to install MongoDB 4.2 Community Edition on macOS systems.

Tap the MongoDB Homebrew Tap

brew tap mongodb/brew

Install the latest available production release of MongoDB Community Server. This will currently install MongoDB 4.2.x:

brew install mongodb-community

Install the latest 4.2.x production release of MongoDB Community Server and command line tools:

brew install mongodb-community@4.2

Install the latest 4.0.x production release of MongoDB Community Server and command line tools:

 brew install mongodb-community@4.0

Install the latest 3.6.x production release of MongoDB Community Server and command line tools:

brew install mongodb-community@3.6

Only install the latest mongo shell for connecting to remote MongoDB instances:

 brew install mongodb-community-shell

Default Paths for the mongodb-community Formula

In addition to installing the MongoDB server and tool binaries, the mongodb-community formula creates:

a configuration file: /usr/local/etc/mongod.conf
a log directory path: /usr/local/var/log/mongodb
a data directory path: /usr/local/var/mongodb

Starting the mongodb-community Server

Run mongod as a service
To have launchd start mongod immediately and also restart at login, use:

brew services start mongodb-community

If you manage mongod as a service it will use the default paths listed above. To stop the server instance use:

brew services stop mongodb-community

Start mongod manually

If you don’t want or need a background MongoDB service you can run:

mongod --config /usr/local/etc/mongod.conf

Note: if you do not include the --config option with a path to a configuration file, the MongoDB server does not have a default configuration file or log directory path and will use a data directory path of /data/db.

To shutdown mongod started manually, use the admin database and run db.shutdownServer():

mongo admin --eval "db.shutdownServer()"

Localhost Binding

Starting with MongoDB, MongoDB binaries, mongod and mongos, bind to localhost by default.

When bound only to the localhost, these binaries can only accept connections from clients that are running on the same machine. Remote clients cannot connect to the binaries bound only to localhost.

MongoDB Client

Some popular MongoDB Client software you can now use: NoSQLBooster, MongoDB Compass, 3T Studio

#mongodb #nosql

How to Install MongoDB 4.x on MacOS with Homebrew
2 Likes134.60 GEEK