Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

couldn't connect to server 127.0.0.1 shell/mongo.js

when i setup mongodb in my ubuntu , i try : ./mongo it show this error :

 couldn't connect to server 127.0.0.1 shell/mongo.js 

so what can i do ,

thanks

like image 902
zjm1126 Avatar asked Apr 20 '11 05:04

zjm1126


People also ask

Why MongoDB Cannot connect to server?

These are some of the solutions: Ensure that your MongoDB instance is running: Compass must connect to a running MongoDB instance. Also check you have installed MongoDB and have a running mongod process. You should also check that the port where MongoDB is running matches the port you provide in the compass connect.

Can't connect to server connection refused MongoDB?

Normally this caused because you didn't start mongod process before you try starting mongo shell. This case worked out for me, i had to do ~>sudo mongod --dbpath /dbpathlocation and then opened the new terminal to run mongo...

How connect mongo shell to server?

To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.


1 Answers

  • Manually remove the lockfile: sudo rm /var/lib/mongodb/mongod.lock
  • Run the repair script: sudo -u mongodb mongod -f /etc/mongodb.conf --repair

Please note the following:

  • You must run this command as the mongodb user. If you run it as root, then root will own files in /var/lib/mongodb/ that are necessary to run the mongodb daemon and therefore when the daemon trys to run later as the mongodb user, it won't have permissions to start. In that case you'll get this error: Unable to create / open lock file for lockfilepath: /var/lib/mongodb/mongod.lock errno:13 Permission denied, terminating.
  • On Ubuntu, you must specify the configuration file /etc/mongodb.conf using the -f flag. Otherwise it will look for the data files in the wrong place and you will see the following error: dbpath (/data/db/) does not exist, terminating.
like image 158
Fady Mohamed Othman Avatar answered Oct 19 '22 22:10

Fady Mohamed Othman