Mongo DB: JavaScript execution failed: Error: couldn’t connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112

if following error appear when try to start mongo in Linux

JavaScript execution failed: Error: couldn’t connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112

here is the solution:

Open Terminal and type following command
First Stop service

sudo service mongodb stop

Then remove the Mongo log file with following

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

then change the permission of the Mongo Library and give full control to mongodb

sudo chown -R mongodb:mongodb /var/lib/mongodb/

Finally start Mongo service

sudo service mongodb start

(update)

For windows,

  • go to services.msc stop MongoDB service.
  • then go to your data directory of Mongodb
  • there is one “.lock” file, delete it.
  • start MongoDB service
  • Done

Leave a Reply

Your email address will not be published. Required fields are marked *