Recently I’ve got the following issue:

connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1

Obviously, as most error messages, above is not clear about the root cause. Finally, I’ve resolved it by using following steps:

  1. Go to /usr/local/var/mongodb
  2. Remove file mongod.lock. On MacOS: rm mongod.lock
  3. Restart MongoDB using brew command (if MongoDB were installed using brew): brew services restart mongodb-community

I hope this helps someone to save their time in finding a solution to that issue.

Comments

You can leave a response, or trackback from your own site.

Before you add comment see for rules.

Leave a Reply

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

4h8f6x