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 https://raw.githubusercontent.com/Homebrew/install/master/install)"
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:
Mongo
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