Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

 I just installed mongoDB on my ubuntu 14.0.4 operating system. I tried to start the shell but I'm getting a connection refused error. Please refer the following code:

me@medev:/etc/init.d$ mongo

MongoDB shell version: 2.6.5

connecting to: test

2014-11-10T15:06:28.084-0500 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused

2014-11-10T15:06:28.085-0500 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146

exception: connect failed

So I restart the service but that's failing too. I get the following error message:

me@medev:/etc/init.d$ sudo service mongodb restart

mongodb: unrecognized service

me@medev:/etc/init.d$ 

This is what I have in my /var/log/mongodb/mongod.log - http://pastebin.com/MrHt8tce

I have also deleted the lock file and then re-run the command but it still fails as you can see below:

me@medev:/var/lib/mongodb$ sudo rm mongod.lock 

me@medev:/var/lib/mongodb$ ls

journal  local.0 local.ns  _tmp

me@medev:/var/lib/mongodb$ sudo service mongodb start

mongodb: unrecognized service

But I can start it using /etc/init.d as you can see below:

me@medev:/var/lib/mongodb$ sudo /etc/init.d/mongod start

Rather than invoking init scripts through /etc/init.d, use the service(8)

utility, e.g. service mongod start

Since the script you are attempting to invoke has been converted to an

Upstart job, you may also use the start(8) utility, e.g. start mongod

mongod start/running, process 27469

me@medev:/var/lib/mongodb$ ls

journal local.0  local.ns mongod.lock

me@medev:/var/lib/mongodb$ mongo

MongoDB shell version: 2.6.5

connecting to: test

> db

test

Any ideas on why I can't start it using the service command would be appreciated. From what I've read, i should be using sudo service mongodb

1 Answer

0 votes
by (108k points)
edited by

In your case what you can do first check the status of your MongoDB service:

/etc/init.d/mongod status

Or

sudo service mongod status

If the service doesn’t get started, in that case, replace the following code:

>service mongod start

With this:

>start mongod

If you want to learn more about MongoDB then go through this MongoDB course for more insights.

Related questions

Browse Categories

...