KeplerGrid guide

Fix MongoDB ECONNREFUSED on localhost

Check whether MongoDB is listening, whether the port is right, and which loopback address your desktop client is using.

Check the exact address and port

A refusal means the attempted TCP connection was rejected. First check the address in the error and make sure a MongoDB process is listening there. Try the same address in mongosh.

mongosh "mongodb://127.0.0.1:27017/?serverSelectionTimeoutMS=2000" --quiet --eval 'db.runCommand({ping:1})'

With a server on that address, the ping returns ok: 1. A stopped process or an unused port can return ECONNREFUSED. Restore the development service or correct the port, then run Test connection again.

KeplerGrid Test connection reports a refused local MongoDB endpoint.
The connection test points to the local MongoDB connection step.

Check IPv4, IPv6 and container mappings

If the error names ::1 and your server listens only on IPv4 loopback, try 127.0.0.1. Use [::1] in a URI when your server actually listens on IPv6 loopback. In Docker, use the host-side published port. Inside an SSH tunnel, a loopback address refers to the SSH server.

Read the next failed check

A client can report a server-selection timeout while listing a refusal among the individual member errors. Look at the reported host and port. Once TCP works, a TLS or authentication error points to a later step.

Connect to Docker · Check authentication after TCP works