What is MongoDB
MongoDB is an open-source document database that belongs to a family of databases called NoSQL – not only SQL and provides high performance, high availability, and automatic scaling. Its document-oriented data model makes it easier to split up data across multiple servers.
This is different than SQL databases, Relational databases, like PostgreSQL, MySQL and, where fields correspond to columns in a table and individual records correspond to rows.
How to install MongoDB on MAC OS X
Install and update Homebrew – a package manager
- Open a new terminal and check if Homebrew is already installed on your computer
- Homebrew is a package manager which is used to install other software/packages on Mac It is like apt-get in Linux OS
- Run command in your terminal to check if Homebrew is already installed:
- If you are not able to install it, try Homebrew Installation by running the command
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Brew update and check the updated version using
brew -v //If not installed sudo /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" //update latest version brew -v
Install and Run MongoDB with Homebrew
- After updating Homebrew install MongoDB by running the command:
brew install mongodb
- Now create a Mongo data directory, This directory is where MongoDB stores database files, using the command:
sudo mkdir -p /data/db
- Make sure that the /data/db directory has the right permissions, run the chown command to give the right access:
sudo chown -R `id -un` /data/db
brew install mongodb sudo mkdir -p /data/db sudo chown -R `id -un` /data/db
Run MongoD and Mongo
- To Start a Mongo process first run the Mongo daemon, in one of your terminal windows run
mongod. This should start the Mongo server.
- Now Run the Mongo shell, with the Mongo daemon running in one terminal, type
mongoin another terminal window. This will run the Mongo shell which is an application to access data in MongoDB.
- Great !! MongoDB is up and running now
- To stop type
ctrl+cin mongo daemon terminal
mongod //in one of your terminal mongo //in another terminal
Set Mongo as a service on Mac
- Most importantly to run mongo as a service first stop mongo and mongod by using
- To run Mongo daemon as a service run command:
brew services start mongodb
- After successfully run the command, Now restart the computer to set mongo as a service
brew services start mongodb //to run mongo as a service on mac
I am sure this article helps you to install MongoDB on Mac OS using Homebrew. Step by Step points will help you to install and understand the process within minutes. I would like to hear your thoughts. Happy learning…