1

MongoDB shell version v4.4.3 connecting to: mongodb://127.0.0.1:27017/admin?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 :: No connection could be made because the target machine actively refused it. : connect@src/mongo/shell/mongo.js:374:17 @(connect):2:6 exception: connect failed exiting with code 1

I get this error when I try to run my mongo server, It has worked previously but not it doesn't. I have no idea what to do, please help.

olaf
  • 342
  • 2
  • 10

3 Answers3

0

This error can come up for a couple reasons. If I were to begin troubleshooting this connection, I would try restarting the MongoDB service on your local computer; as it looks like you are trying to connect to a local instance of mongodb.

  • Hello, I have no idea how so can you elaborate. – olaf Feb 10 '21 at 20:52
  • Sure. So restarting the service depends on the operating system of your computer, and a few other things, If you have installed MongoDB locally on your Windows computer, open a powershell or command prompt window with admin privileges' and type in the following command: `net service stop mongodb` then the command `net service start mongodb` – Quibfiddle Feb 10 '21 at 21:02
0

The reason for this error is, you have stopped the mongodb server. Follow these steps to start mongodb server. First open task manager and go to the services tab. Then check the server status. If it is stopped, right click on it and start. enter image description here

Amila
  • 1
0

IF you are on window then go to your directory where server files is there. under that check that mongod.lock file have some value.

Kindly delete the file After that try to delete the service and then recreate the service Delete service:

sc delete mongodb

ReCreate the Service:

sc.exe create arbiter binPath= "\"C:\Program Files\MongoDB\Server\4.4\bin\mongod.exe\" --service --config=\"C:\data\mongodb.cfg\"" DisplayName= "mongodb" start= "auto"

Now start the service with the command

net start mongodb

Please give the comment about your attempt. I will be happy to help if problem not solved.

Aks
  • 1,092
  • 3
  • 12
  • 29