Is your MongoDB properly running? A simple way to check it would be with:

service mongod status

On my CentOS 5.x it gave:

mongod dead but subsys locked

There are two possible causes I could find. First is related to disk space. If you do not have enough space for dbpath (database directory) then you may get this message.

To solve it you can add following to the config file provided when running mongod --config mongod.conf

For MongoDB 3.x (latest version)

storage:
   mmapv1:
      smallFiles: true

For version 2.6+

storage:
   smallFiles: true

For version 2.4 and less

smallfiles = true

Then just execute mongod to accept your config file (here it assumes that location of the config is /etc/mongodb.conf):

mongod -f /etc/mongodb.conf

Documentation for smallfiles parameter:

Set to true to modify MongoDB to use a smaller default data file size. 
Specifically, smallfiles reduces the initial size for data files and
limits them to 512 megabytes. The smallfiles setting also reduces the
size of each journal files from 1 gigabyte to 128 megabytes.
Alternatively you can run mongod with --smallfiles parameter like:
mongod --smallfiles

On my machine the problem was different. It was expecting a directory /var/lib/mongod with proper permissions, which was not there. The solution is simple:

sudo mkdir /var/lib/mongod
sudo chown -R mongod /var/lib/mongod

However how did I find out about the problem(s) in the first place. Again the solution is very simple. I looked in the log file:

vi /var/log/mongodb/mongodb.log

Always start with the log file.

Finally you can verify that your system is running properly with:

sudo service mongod status

After fixing it gave:

mongod (pid 26194) is running...

Now that’s solved, let’s get back to mongodb coding..