Mongodb is most popular today, it is a no-sql database. This article will tell you how to install it on MacOS correctlly.
1. Install Mongodb On Mac.
- Download Mongodb for MacOS version.
- Unzip the download file to a local folder.
- Add Mongodb bin folder into the PATH environment variable value with following steps in terminal.
# Go to user home directory. 192:~ $ cd ~ # Edit user profile file, add Mongodb bin folder to the PATH env variable value. 192:~ $ vim .bash_profile # Make environment variable change take effect. 192:~ $ source .bash_profile # Display new environment variable to verify the PATH value has been changed. 192:~ $ env PATH=/Users/zhaosong/Downloads/mongodb-osx-x86_64-4.0.2/bin:
2. Start Mongodb Server.
- Open a terminal and run
mongodcommand in it.
192:~ $ mongod
- If you meet bellow error message, that means it can not find the /data/db folder, mongodb need this folder to run.
exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
- Create /data/db folder with below command in terminal.
sh-3.2# mkdir /data sh-3.2# cd data sh-3.2# mkdir db
- Now run
mongodcommand in terminal again, the mongodb server will start successfully.
- The db server used default port number is 27017.
3. Connect Mongodb.
- Now the mongodb server has been started successfully.
- You can run
mongocommand in a terminal to connect it.
- Besides command, you can also use Mongodb GUI client Mongodb Compass to manage the no-sql database.
- Download Compass to local folder and install it.
- It will add an icon in MacOS desktop, click to open it.
- Select None in the Authentication drop down list then click Connect button.
- After successfully login, you can click Create Database button to create a database. Input database name and collection name. In this example, i create database user_account and the collection name is same.
- Click database user_account to go into it, then click user_account collection, now you can insert, update, delete or query document in it.
- After insert a document, you can edit the fields in the document. Just click the edit button at record right, then click the plus button at each line beginning. There will popup Add Field After menu item. Click it to add a field. After edit document, click UPDATE button to save the changes.
(Visited 14 times, 1 visits today)