Tags

, , ,

I have started this series of posts with two goals, record the information for my future use and maybe to help someone starting with these technologies. So, enough chit-chat, let’s move to the business.

What is MongoDB? MongoDB is an open-source, document database designed for ease of development and scaling. The current version is 3.2.

This small tutorial serve as a guide on how to install MongoDB on Mac OSX.

This is the easiest part. The documentation of MongoDB covers all you need to install it over the OSX. Using the Homebrew package manager, all that you need to do is opening a terminal and run the following commands.

brew update
brew install mongodb

This will install MongoDB in the following location:

/usr/local/var/Cellar/mongodb/

In fact, you do not need to interact with this folder to use MongoDB, this is just a complimentary information. In this folder you will find the binary folder and the README file.

Once you have download and installed, you can check if MongoDB is working by running the following command.

mongo -version
mongo -help

If the installation was succeed, you should see something similar to this:

Screenshot 2016-02-02 21.18.16

 

The second step is create the database folder. MongoDB store data into the /data/db folder, you need to create this folder manually and assign proper permission.

$ sudo mkdir -p /data/db
$ whoami
agabardo
$ sudo chown agabardo /data/db

Next step is adding mongodb/bin to $PATH

$ cd ~
$ pwd
/Users/agabardo
$ touch .bash_profile
$ vim .bash_profile
export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin

At this point, if you try mongo -version you should see something similar to this

Screenshot 2016-02-06 19.58.49

Now, open another terminal and start MongoDB with $ mongod. (In case of trouble with permissions you can use $ sudo mongod).

Screenshot 2016-02-06 20.03.29

When you see the message: ‘waiting for connections on port 27017′ means that MongoDB is up and running. Now in another terminal window let’s tryMongoDB shell typing.

$ mongo

The result should be similar to this.

Screenshot 2016-02-06 20.12.24

MongoDB is up and running. In the next post we will import the example database and select some data. I hope the small tutorial can help someone else. The step that is skipped in the official documentation that is how to set the permissions and export the Path is complimentary to the documentation. If find more help here on MongoDB website.

Advertisements