ECONNREFUSED - 127.0.0.1 to localhost

sir,
“I am in a big trouble. Can you please help me to solve this? When I try to connect MongoDB to my local server, it’s not connecting but the code is still running. So, I decided to change the IP address from “127.0.0.1:27017” to “localhost”. However, this time it shows an error “ECONNREFUSED”. What should I do? I have watched more than 30 videos on YouTube and tried everything, but still have not found a solution. I have also checked after turning off the firewall and tried another network connection. Please help.”

Not able to connect but code is running means?
How did you try to connect? By mongo/mongosh?
Is your mongod up?

Thank you for your reply. I am showing my source code here. However, when I run this code, my terminal doesn’t display any output or response.

  • Does your connection eventually timeout? This will happen if your mongod process is not running.
  • In your powershell window, what is the results of running Test-NetConnection 127.0.0.1 -Port 27017?

I’ve tried all the solutions to connect to MongoDB Community Server on my system, but it isn’t working at all

  1. Restarting the Mongo Server from services.msc
  2. Using 0.0.0.0 instead of localhost
  3. Using 127.0.0.1 instead of localhost

I tried even using 127.0.0.1:27017

Compass and MongoShell are also able to connect,

How should I solve this ?

(::1) in your error message indicates it is trying to connect with Ipv6 address Switching to 127.0.0.1 should work
Try to remove ipv6 entry from your config and use ipv4 only
or it could be your node.js version
Did you try upgrade/downgrade version?

Last night when I tried all these solutions it didn’t work
But it miraculously worked today. :rofl:


plz help everythings is ok username and password

Is your cluster up?
Can you connect to your cluster with shell?

Can you show your MongoDB config file?

same scene happened to me, literally!! :rofl: