couldn't connect to server 127.0.0.1 shell/mon

2019-01-07 04:51发布

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

13条回答
祖国的老花朵
2楼-- · 2019-01-07 05:38
sudo rm /var/lib/mongodb/mongod.lock   
sudo -u mongodb mongod -f /etc/mongodb.conf --repair 
sudo service mongodb start

Here is all, sometimes, it takes a little while to start mongo after performing these operations.

查看更多
仙女界的扛把子
3楼-- · 2019-01-07 05:38

Either your mongod is not running (check using "ps" command) or it is listening on some outside IP address and not on localhost. So first check the process list if 'mongod' is running. If yes, check with "netstat -nap" for the related port.

Of course you can start mongod on the console manually or even look into the mongod logfile (if there is one configured...depending on how you installed mongod).

查看更多
劳资没心,怎么记你
4楼-- · 2019-01-07 05:38

On Ubuntu, try this:

sudo invoke-rc.d mongodb start
查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-07 05:39

This is actually not an error... What happens here is that Mongo relies on a daemon in order to run the local database server, so in order to "fire up" the mongo server in your shell, you have to start the mongo service first.

For Fedora Linux (wich is the Distro I use) You have to run these commands:

1 sudo service mongod start
2 mongo

And there you have it! the server is going to run. Now, If you want Mongo service to Start when the system boots then you have to run:

sudo chkconfig --levels 235 mongod on

And that's all! If you do that, now in the shell you just have to type mongo in order to start the server but that's pretty much it, the problem is you have to start the SERVICE first and then the SERVER :)

P.S. The commands I posted might work on other linux distros as well, not just in fedora... In case not maybe you have to tweak some words depending on the distro you're using ;)

查看更多
地球回转人心会变
6楼-- · 2019-01-07 05:39

First you have to make sure that all the files and directories in your /var/lib/mongodb/ folder (or whichever folder dbpath points to) belong to the mongodb user and mongodb group.

cd /var/lib/mongodb/
sudo chown mongodb filename.*
sudo chgrp mongodb filename.*
sudo chown -R mongodb directory
sudo chgrp -R mongodb directory

(Replace filename and directory with their respective names)

Then you can remove the lock, repair the database and restart the daemon as other people already mentioned:

sudo rm /var/lib/mongodb/mongod.lock   
sudo -u mongodb mongod -f /etc/mongodb.conf --repair 
sudo service mongodb start
查看更多
We Are One
7楼-- · 2019-01-07 05:41

I got the same problem when I tried to install mongo. I got Error as,

Error

"Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84"

Solution:

First install mongod by using:

sudo apt-get install mongodb-server

Then type

mongod --dbpath /mongo/db

Then

sudo rm /var/lib/mongodb/mongod.lock

Then

sudo -u mongodb mongod -f /etc/mongodb.conf  --repair

Thank You

查看更多
登录 后发表回答