Wednesday, December 14, 2011

As stated in previous post on MongoDB, once installed, user can verify by opening shell & by typing mongo. It will by defualt connect with the table test (which is not a one you created obviously) like below if everything worked properly during installation.

Before moving on to remote access, better to know few very basic commands to check what you really wants to know.Typeshow dbswhich will show what are the existing databases. Then if you want to use existing one or new one typeuse dbnamewhich will not create a database at the exact moment but on the fly if it does not exist. In mongodb table is considered a collection. Actually here, this is not exact same as the table in RDBMS but for clarity consider it is so. For to view all the collections in used database type show collections& to use one, type use collectionname. To view all the data inside of selected collection, typedb.collectionname.find(). Here in mongodb, once you selected a database, when querying with collection you always has to use the reference of the database with query. That is why you have to use db.$what_ever_the_bla_blanext. You can find sql to mongodb mapping relationship page here.

Now let's move to setting up a remote connection to a mongodb server. It is better to have two terminals. One to start server & listening on incoming requests. Second to locally execute & view whether remote calls have worked (optional).

To start server

1. Create a directory structure in root sudo mkdir -p /data/db

2. Grant user permission to itsudo chown `id -u` /data/db

3. Run mongo server to listen on incoming connectionsmongod

You will noticed that sever is starting & saying it is listening on portas indicated in below image.

But If the result is like below

Then do the following.

4. Find mongodb PID & kill it.ps -eF | grep 'mongo\|PID'

5. You can see in first shell image, I have executed this command & obtained the ID 1143. Next is to kill that process.

sudo kill “PID_VALUE”

Re-run the mongodb server: mongod

This is because if mongodb was installed using sudo apt get install, it will always run each time machine reboots. Therefore before server starts up, already running process has to be killed. Then server will start properly and keep on listening for incoming connections. To connect to a remote server simply typemongo remoteIPaddressafter starting the mongodb server on both sides.To get mongodb execution status use sudo status mongodb

From now on there are plenty of enough resources available to continue with mongodb. Go after & enjoy the power of mongo.

Monday, December 12, 2011

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.

Installation1. Add MongoDB repository into Ubuntu assuming installed ubuntu version is 10.10Add below line any where of source.list file.

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 -stableTest by run command mongo and you will get MongoDB shell versionNow 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 DriverBefore 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.