Errr 'mongo.js:L112 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112'

后端 未结 8 1197
别那么骄傲
别那么骄傲 2021-01-30 01:25

I can\'t connect to MongoDB. In Ubuntu it works, but I\'m working in CentOS now. This is the error message:

MongoDB shell version: 2.4.2
connecting

8条回答
  •  借酒劲吻你
    2021-01-30 01:34

    This method only works if you want to repair your data files without preserving the original files. To find where you dbpath resides, use

    vim /etc/mongodb.conf
    

    Check for option dbpath=.

    (I have dbpath=/var/lib/mongodb.)

    Default: /data/db/

    Typical locations include /srv/mongodb, /var/lib/mongodb or /opt/mongodb.

    Replace the /var/lib/mongodb with your dbpath

    sudo rm /var/lib/mongodb/mongod.lock
    sudo mongod --dbpath /var/lib/mongodb/ --repair
    sudo mongod --dbpath /var/lib/mongodb/ --journal
    

    (Make sure that you leave you terminal running in which you have run the above lines. Don't press Ctrl + C or quit it.) Type the command to start mongo now in another window.

    I hope this works for you! For those who want to repair your data files while preserving the original files, see mongo recover.

提交回复
热议问题