0

I'm starting MongoDB using the following command:

sumeet@sumeet-acer:~$ sudo service mongod start

I get a reply as:

mongod start/running, process 7209
sumeet@sumeet-acer:~$ 

But when I try to enter MongoDB shell by typing mongo I get the following error:

sumeet@sumeet-acer:~$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Fri Jun 12 14:01:59 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125
Sumeet Masih
  • 597
  • 1
  • 8
  • 22

3 Answers3

0

By default, mongod and mongos use the 27017 port. Without any option, the client will try to connect to a server running on localhost and listening at that port.

A few general advices here:

  1. check if the mongod server is really running (ps -edf | grep mongod);
  2. check if it uses the default port (look in the config file1, or use nmap localhost -p0-65535 or netstat | grep 27017);
  3. if mongod is not running, check in the log2 for clues about what goes wrong.


1 /etc/mongodb.conf (on Debian-like systems at least)
2 /var/log/mongodb (on Debian-like systems at least)
Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125
0

The default IP and Port for MongoDB is 127.0.0.1 & 27017.

If you are using config file for specifying settings than re-verify IP & Port mentioned in it.

If you are going with default option than mongod should function as expected.

try mongo 127.0.0.1:27017

Pradeep
  • 1,108
  • 1
  • 15
  • 31
0

this worked for me For MongoDB 2.2.2 running on Ubuntu 12.10, it's in /var/lib/mongodb/mongod.lock

and after that running the repair command

sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/

courtesy: https://stackoverflow.com/a/13700262/4907105

Community
  • 1
  • 1
Sumeet Masih
  • 597
  • 1
  • 8
  • 22