Can't ping localhost MongoDB running as a Windows Service

I’m attempting to set up a database server for an app using Node.js. I installed mongoDB as a windows service and I’ve successfully connected to the database server using MongoDB Compass.

When attempting to connect to the service from my localhost either via my Node.js app or just attempting to ping it via ‘telnet 127.0.0.1 27017’ I get a refused connection error.

I’ve verified that the MongoDB server is spinning up by looking at the startup logs in MongoDB Compass. It is successfully registering all changes to config files etc. and I can visualize it listening on the specified port/IP address. I have also turned off my windows firewall in addition to creating a rule to bypass it when it was on.

I have tried several iterations in the mongod.cfg recommended in most forum posts etc… and none of them seem to be working. I.e.

bindIp=0.0.0.0 or bindIp=127.0.0.1. My current configuration is

network interfaces

net:
port: 27017
bindIp: 127.0.0.1

setParameter:
enableLocalhostAuthBypass: true

Edit: Should clarify that I see nothing output in the logs for MongoDB whenever I fail to ping/connect via my Node.js app. I do see a significant amount being logged when I connect via MongoDB Compass. I have also attempted to send a post to the server via PostMan and these are the results.
http://localhost:27017
body: { “Status” : “Posting” }

*from the logs
{“t”:{“$date”:“2024-03-24T09:46:52.012-04:00”},“s”:“I”, “c”:“NETWORK”, “id”:22943, “ctx”:“listener”,“msg”:“Connection accepted”,“attr”:{“remote”:“127.0.0.1:63524”,“uuid”:{“uuid”:{“$uuid”:“519c73da-9f1c-490b-8b82-9fdcb0412a7e”}},“connectionId”:21,“connectionCount”:14}}
{“t”:{“$date”:“2024-03-24T09:46:52.012-04:00”},“s”:“I”, “c”:“EXECUTOR”, “id”:22988, “ctx”:“conn21”,“msg”:“Error receiving request from client. Ending connection from remote”,“attr”:{“error”:{“code”:141,“codeName”:“SSLHandshakeFailed”,“errmsg”:“SSL handshake received but server is started without SSL support”},“remote”:“127.0.0.1:63524”,“connectionId”:21}}
{“t”:{“$date”:“2024-03-24T09:46:52.012-04:00”},“s”:“I”, “c”:“NETWORK”, “id”:22944, “ctx”:“conn21”,“msg”:“Connection ended”,“attr”:{“remote”:“127.0.0.1:63524”,“uuid”:{“uuid”:{“$uuid”:“519c73da-9f1c-490b-8b82-9fdcb0412a7e”}},“connectionId”:21,“connectionCount”:13}}

Any help would be much appreciated as I feel I’ve exhausted all of my options as far as research goes. Thanks in advance.

What does the node.js connection code and options set look like?

If you can connect with compass and view databases / collections then it suggests that the server is fine and it’s just the node connection is upset.

You say that nothing is in the logs when your app cannot connect, but that error message from the logs, is that from a compass connection or your app failing to connect?

Other things I thought are, are you trying to force an SSL connection but not set this up on the server (from the log message above) and if nothing can connect, are you running IP4 and IP6 protocols on the windows box? Search the forums for IP6 to see related posts.

Here is a screenshot of the code. However, I’m also unable to ping the server from terminal so I’m not sure the code is the problem.

The logs in my post above were specifically only generating when I would attempt to post to the server using postman. Attempts to ping the server/connect using the app don’t generate any log messages.

Also I’m pretty sure my PC has ipv4 and ipv6 enabled.

Edit:
I have since also successfully connected to the DBServer using the same connection string as in my app via mongosh. Just unable to successfully establish a connection any other way.

Been troubleshooting a while longer and I think the following is worth mentioning. My app and pings are both coming through WSL. I went ahead and changed the port/IP to 0.0.0.0:27017, but still getting the same failures.

I’ve also gone through the process of moving MongoDB from a Windows Service into a standalone to potentially give some additional information but no luck.

I’m starting to think that maybe WSL is the problem here, however, the app should now be open to requests from anywhere.

After further investigation into WSL. I finally figured out the issue. Turns out WSL has an alternate IP that it uses for localhost.

Glad you got it sorted, so the app was running under WSL and the server was running as a service on windows then?

Something to watch out for, I’ve not used WSL that much but recall setting it up that it was just like running a VM so it makes sense!