Navigation

Install MongoDB Community Edition on macOS

Overview

The following tutorial uses brew to install MongoDB 3.6 Community Edition on macOS systems. To install a different version of MongoDB, please refer to that version’s documentation.

Note

Starting with MongoDB 3.6, MongoDB binaries, mongod and mongos, bind to localhost by default. From MongoDB versions 2.6 to 3.4, only the binaries from the official MongoDB RPM (Red Hat, CentOS, Fedora Linux, and derivatives) and DEB (Debian, Ubuntu, and derivatives) packages would bind to localhost by default. To learn more about this change, see Localhost Binding Compatibility Changes.

Platform Support

Note

MongoDB 3.6 is not tested on APFS, the new filesystem in macOS 10.13 and may encounter errors.

MongoDB only supports macOS versions 10.7 (Lion) and later on Intel x86-64.

See Supported Platforms for more information.

Install MongoDB Community Edition

Prerequisite

If you have previously tapped the official MongoDB formula repository, you can go directly to the Install MongoDB step.

If you have not previously tapped the official MongoDB formula repository, tap the official MongoDB formula repository to add to the formula list. From a terminal, issue the following:

brew tap mongodb/brew

Install MongoDB

From a terminal, issue the following:

brew install mongodb-community@3.6

In addition to the binaries, the install creates:

Run MongoDB

From a terminal, issue the following to run MongoDB (i.e. the mongod process) in the foreground.

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

Alternatively, to run MongoDB as a macOS service, issue the following (the process uses the /usr/local/etc/mongod.conf file, created during the install):

brew services start mongodb-community@3.6

Connect and Use MongoDB

To begin using MongoDB, connect a mongo shell to the running instance. From a new terminal, issue the following:

mongo

For information on CRUD (Create,Read,Update,Delete) operations, see: