Article Directory
One, install MongoDB
1. Download address
Official website download address: https://www.mongodb.com/download-center/community
2. Download and install
Click the [Download] button, put the decompressed mongodb-osx-x86_64-4.0.10 file into /usr/local, and name the file MongoDB (by default, the /usr directory is not visible in the Finder , You can open the Finder and press command + space to enter /usr/local and press Enter to see this directory).
3. Configure system environment variables
Open the terminal, type open -e .bash_profile
, type in the opened file export PATH=${PATH}:/usr/local/MongoDB/bin
, save and close the .bash_profile file.
4. Check if the installation is successful
Then enter "source .bash_profile" in the terminal and press Enter to make the configuration effective, then enter "mongod -version", and then press Enter. If you see the version number below, it means that MongoDB has been installed successfully.
5. Create a MongoDB data repository
Enter in the terminal sudo mkdir -p /data/db
, create a new data folder, and create a db folder inside
Second, run MongoDB and solutions to problems during installation
1. Start the mongodb server
Open the terminal input mongod
(note the input mongod
, not mongodb
) start the mongodb server
1.1. If the situation as shown in the figure below appears, the startup is successful!
1.2. (If the startup is successful in step 1.1, you can ignore this step) If an error is reported as shown in the figure below, it means that the startup is not successful:
Solution
Shown above was created / data / db has only read, not write permission, so give db add this folder permissions,
and then navigate to the data directory, executesudo chmod 777 db
to the db set to a highest authority, or execute sudo chown Your username is /data/db.
Then execute mongod again to successfully open the server.
2. Check whether the link server is successful
Open the browser, enter localhost:27017 in the address bar, and the situation as shown in the figure below appears, which means that the connection to the server is successful.
Three, install MongoDB visualization tool
1. Download
Download link: https://www.mongodb.com/download-center/compass
2. Install and link MongoDB database
Click [Download] to download and install, then click [CONNECT]
As shown in the figure below, it means that the connection to the database is successful.
If the situation shown in the figure below appears, it means that the MongoDB server is not started, and you need to enter it in the terminal to mongod
start the MongoDB server.