Monday, December 12, 2011

MongoDB | Document Oriented, No SQL open source database - Part 1

OBJECTS. It is all about dealing with objects. That is, storing them, retrieving them back, updating them PLUS encoding, efficient indexing, replica managing etc.  Typical object can have its own as well as inherited feature sets. These can be considered as key value pairs like below.

    "username" : "bob",
    "address" : {
        "street" : "123 Main Street",
        "city" : "Springfield",
        "state" : "NY"
Above is an example of simple nested JSON object. When remote method invocation or inter process communication happens, by using this kind of mechanism to send data can be more convenient. When received, by querying, storing data back in SQL databases is not needed if there exits a secure, storage effective  document oriented querying language. That is where MongoDB fits with BSON format. It is a cross language database system yet to come with more features. BSON helps to store JSON objects as binary objects which reduce size & increase indexing & retrieving performance.

In this post, a simple working scenario for successfully installing mongoDB on Linux based operating system (basically on Ubuntu 10.10) will be discussed.


1. Add MongoDB repository into Ubuntu assuming installed ubuntu version is 10.10
Add below line any where of source.list file.
deb 10.10 10gen into /etc/apt/source.list.

2. Create PGP key and Install MongoDB
We need to generate key to gain access into MongoDB repository.
Use sudo apt-key adv --keyserver --recv 7F0CEB10 to get keyserver
Then do sudo apt-get update to update your repository.

3. Do sudo apt-get install mongodb-stable to install mongoDB into your Ubuntu.
If that didnt work, use just sudo apt-get install mongodb instead of -stable
Test by run command mongo and you will get MongoDB shell version

Now we have to configure mongoDB with PHP Driver so that you can interact with mongoDB programetically via server-side scripting language.

4.  Configure MongoDB PHP Driver
Before configure mongoDB PHP driver, first need to have build-essential, php5-dev and php-pear.
To install those:
sudo apt-get install build-essential php5-dev php-pear

**remember to tick on first two updates in software updates/updates in synaptic package manager. Otherwise system will not download all the packages needed & later steps will fail.

5. Then install pecl driver for mongo (For connecting with PHP)
sudo pecl install mongo

6. Add Mongo Extension into php.ini
In the end of line, add into /etc/php5/apache2/php.ini.

7. Restart apache by
sudo service apache2 restart

8. Check with phpinfo() to see if MongoDB already installed.

From next post, How to get remote accessibility by starting mongoDB server & checking it out via remote mongoDB terminal will be discussed. 

Good Luck :)

No comments: