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.

To install a different version of MongoDB, please refer to that
version’s documentation. To install the previous version, see
the tutorial for version 3.6.

Note

You can also spin up MongoDB on AWS, Azure, or GCP using Atlas, our
fully-managed database-as-a-service. Atlas enables you to configure anything
from a free sandbox environment to a globally sharded production cluster.
Set up a free cluster now.

Homebrew installs binary packages based on published
“formulae.” This section describes how to update brew to the latest
packages and install MongoDB Community Edition. Homebrew requires some initial
setup and configuration, which is beyond the scope of this document.

Before you start MongoDB for the first time, create the directory to
which the mongod process will write data. By default, the
mongod process uses the /data/db directory. If you create
a directory other than this one, you must specify that directory in the
dbpath option when starting the mongod process
later in this procedure.

Start a mongo shell on the same host machine as the
mongod. You can run the mongo shell
without any command-line options to connect to a
mongod that is running on your localhost with default
port 27017: