Recently I’ve got the following issue:

connecting to: mongodb://
Error: couldn't connect to server, connection attempt failed: SocketException: Error connecting to :: caused by :: Connection refused :
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.


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 *