Skip to content
Runbook

Install MongoDB on macOS

Document-oriented NoSQL database (BSON), designed for horizontal scalability and flexible schemas.

Databasenosqldocumentdatabasebson

Installation

Server (Community) · Homebrew
brew tap mongodb/brew
brew install mongodb-community

MongoDB is not in the main Homebrew repository: the mongodb/brew tap is required.

Shell only · Homebrew
brew install mongosh

Unnecessary if you installed mongodb-community, which includes mongosh.

Verify the installation

Verify
mongod --version

Service

Start
brew services start mongodb-community
Stop
brew services stop mongodb-community
Status
brew services info mongodb-community
Restart
brew services restart mongodb-community

Important files

TypePathDescription
config/opt/homebrew/etc/mongod.confServer configuration (Apple Silicon; /usr/local/etc on Intel).
data/opt/homebrew/var/mongodbdbPath data directory (Apple Silicon; /usr/local/var on Intel).
log/opt/homebrew/var/log/mongodb/mongo.logServer log.

Default ports

27017

Command-line tools

  • mongoshAdministration and query shell.
  • mongodumpBinary export of a database.
  • mongorestoreRestore of a binary dump.

Uninstall

Uninstall
brew services stop mongodb-community
brew uninstall mongodb-community
brew untap mongodb/brew

Good to know

  • Paths depend on the architecture: /opt/homebrew on Apple Silicon, /usr/local on Intel.
  • Homebrew manages the service via launchd; brew services drives it for you.
  • Security: by default authentication is disabled and the server listens only on 127.0.0.1. Never expose port 27017 without enabling security.authorization and restricting net.bindIp.

Installation on macOS

Homebrew is the recommended path. Homebrew puts mongod on the PATH; mongod --version confirms the server installation, as on the other platforms. After brew services start mongodb-community, the server listens on localhost:27017. Connect with mongosh.

To find the real Homebrew prefix on your machine:

brew --prefix

The configuration and data paths above derive from it ($(brew --prefix)/etc/mongod.conf, $(brew --prefix)/var/mongodb).