Installing and Exploring MongoDB on my Linux Workstation

Having been working with Relational databases for several years now, today I took a dive into the world of NoSQL databases. Having earlier (few weeks ago) explored the environment and learnt about various concepts behind NoSQL and BigData technologies, I decided to have a go at setting up one of the popular databases in the NoSQL space. I took-on the task of installing and exploring MongoDB on my Linux workstation, which is running LinuxMint 15 Cinnamon. Below is a brief blow-by-blow account of what it took.

To Setup MongoDB on LinuxMint, do the following:

1. First, do a quick check to see if the workstation already has any MongoDB version installed on it. Open the Linux command terminal/console-window, and execute the command -

$ mongod

On executing this command, if MongoDB is not yet installed on the workstation, the linux system will return the message - "The program 'mongod' is currently not installed...". Meaning, all clear, so we can go ahead and install a fresh MongoDB instance.

2. Two options exist for installing MongoDB on linux. Option 1 is to use the Package Management system (APT). Option 2 is to install it manually.
Option 2 of installing manually basically entails downloading the tarball from the mongodb download page (http://downloads.mongodb.org), unpacking it and copying the files/folders to a target directory and then adding the bin folder containing the MongoDB binaries to your PATH environment variable, to make the executables accessible. Further manual steps needed include, setting the data Directory (i.e dbpath) and ensuring that the mongodb user account has read/write access to files in this directory.
Now, Option 1, of using the package management system offers a key advantage over option 2. This is because it is a much simpler process and the MongoDB can be easily/automatically updated through the repository, as newer versions are released.

3. To install using the APT package mgmt system (i.e. Option 1), first run the following command to import the MongoDB public GPG Key -

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

4. Create a new repository file for MongoDB at the directory, /etc/apt/sources.list.d/mongodb.list, using the following command - 

$ echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

5. Now, reload the repository by executing - 

$ sudo apt-get update

6. Then, install the latest stable version of MongoDB by executing the command - 

sudo apt-get install mongodb-10gen

7. When the installation is complete, verify the version by running the command - 

$ mongod --version



8. Next, enable MongoDB's RESTful Interface by opening the configuration file at /etc/mongod.conf and adding the line -

rest = true

9. Stop the MongoDB service/daemon by executing -

$ sudo service mongodb stop

10. Restart the service by executing -

$ sudo service mongodb start

11. With the daemon restarted, using a browser navigate to the address - http://localhost:28017/. This is a web interface tool for performing diagnostic and monitoring functions on the MongoDB instance.



12. Open the mongo shell and connect to the MongoDB database server by running the command -
$ mongo
on the system prompt.

13. Within the mongo shell, executing the
> help
command, displays the list of db functions and commands that can be run against the test database; including the command,
> exit
for terminating and quitting the mongo shell.

Voila! MongoDB installation for Linux and quick tour, in a nutshell.

Further exploration and future blogposts on the subject will include, implementing a full-blown database on MongoDB, performing CRUD and other operations against the database, building a complete data-access application on the database and further down the line, implementing a MongoDB cluster with sharding across multiple machines.

Bye for now.

Ps: Comments, Questions and Suggestions are all welcome.
Email: mailto:obkalu[AT]gmail.com

Comments