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

  • 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.

Leave a Comment