Install MongoDB under Mac

Source: Internet
Author: User
Tags brew install mongodb install homebrew install mongodb mongodb sublime editor sublime text

Install MongoDB under Mac

One: Install MongoDB:

Mac installed MongoDB There are two ways, the first is through the source installation, the other is to use homebrew, the following I use homebrew to install, first we need to install homebrew, install Homebrew command as follows:

/usr/bin/ruby-e "$ (curl-fssl"

1. With homebrew installation, the installation command is as follows:

Brew Install MongoDB

2. Start the MongoDB service with the following command:

Brew Services Start MongoDB

3. Close the MongoDB Service command as follows:

Brew Services Stop MongoDB

4. Enter Mongdb, using the following command:


5. Review the Homebrew installation Services, as follows:

Brew Services List

6. MongoDB Directory File

The files that are installed by default are stored under/usr/local/cellar/mongodb, as shown in:

Two: Configure MongoDB

After the installation of MongoDB, you need to do the following configuration MongoDB, otherwise it is not possible to start mongodb;

2.1 Create a new 2 directory in the MongoDB directory, the first is data/db, the function is: for storing data files, the second is etc, for storing mongodb.conf;

Create the data/db data file in the MongoDB root directory, as shown in:

Create the mongodb.conf file as follows:

Use sublime text to open the file mongodb.conf, such as the following command:

sudo open./mongodb.conf-a ' Sublime text ' can be opened using the sublime editor;

Then add the following code under the mongodb.conf file:

#mongodb config filedbpath=/users/wangxi/documents/mongodb/data/db/logpathtrue  = 27017truetrue

2.2 Modifying the System environment variable path
To add the /usr/local/cellar/mongodb/3.6.4/bin directory to path, use the following command:

Echo ' Export path=/usr/local/cellar/mongodb/3.6.4/bin: $PATH ' >>~/.bash_profile

To make the environment variable effective after the add is complete, we reboot the terminal and enter the Echo $PATH on the command line to see if the environment variable was added successfully;

Echo $PATH

Indicates that the environment variable was added successfully.

2.3 Add operation permissions for database log files

sudo chown-r user name/data/db

Such as

3. Start MongoDB

Open the terminal command, go to the bin directory under MongoDB, and use the command./mongod to start the MongoDB service as shown in:

4. Create a new window, enter./mongo try to manipulate the database as shown in:

By now, our server has been successfully started, then we can do it.

Install MongoDB under Mac

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.