4 STEPS to Install MongoDB on Mac
In this quick tutorial, I am going to be showing you how to install MongoDB with the 4 STEPS.
- Install Brew
- Install MongoDB
- Run Mongo Server
- Make A query To MongoDo
STEP #1 Install Brew
Open up your terminal by going to Applications -> Utilities -> Terminal and Copy and Paste the following command into the Terminal. Hit enter to begin installing brew.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
STEP #2 Install MongoDB
Once Brew is installed, it is time to install MongoDB by issuing the following command on the Terminal:
brew install mongodb
Next, create a folder by typing the following command:
sudo mkdir -p /data/db
You will be prompted to enter your computer password. The below command will take you to the folder path that contains all of the mongo server files.
sudo chown yourhomedirectoryname /data/db
That’s it! At this point, you have successfully installed MongoDB on your Mac!
Now, open up two Terminal Windows, one is to run MongoDB Server and other one is Mongo Shell where you can write write Mongo Queries.
STEP #3 Run Mongo Server
Type the command below to start the server.
Now, the server is running. If you want to stop the server, you can use the Control + C keyboard shortcut or close the Terminal window.
STEP #4 Make A Query To MongoDB
Once the server is up and running, open up a new tab in the Terminal window and type the command below that will give you the mongo shell in which you can write mongo queries.
If you want to see all the databases, use the following command.
Sometimes, writing queries on the Mongo Shell would be really hard because there is no syntax highlight and it becomes tedious when you execute big queries.
Luckily, I recently found a mac application called MongoBooster (FREE) that will replace the mongo shell Terminal window. Remember, you must keep the server running.
Once you install MongoBooster, you need to connect to the server by going to File→ Connect→ Create and add your server information.
The server has to be “localhost” and the port is “27017” which is a default Mongo Server port. See the screenshot below:
Once you have successfully connected to the server via MongoBooster, you can start writing Mongo queries in the Mongo Shell which is nice like below.
All you have to do is write some mongo queries on the top window and click RUN button and you can see the result on bottom window.
I really enjoy working with MongoBooster as it gives me code completion and syntax highlight.
Thank You for reading…