Windows10运行Node.js连接MongoDB报MongoNetworkError求助
Hey there, since your code runs fine on other machines, this connection timeout issue is almost certainly tied to your new Windows 10 environment's network or MongoDB setup. Let's walk through the most likely fixes:
Verify MongoDB Service is Running
On Windows, MongoDB typically runs as a Windows service. HitWin + R, typeservices.msc, and look for the service named MongoDB Server (or similar). If it's stopped, right-click it and select "Start". For future reliability, set its startup type to "Automatic" so it launches with your system.Double-Check Your Connection String Details
The error shows you're trying to connect to10.237.141.117:27011. Ask yourself:- Is this the correct IP/port for your MongoDB instance? If it's a local instance, you should be using
localhostor127.0.0.1instead of that 10.x.x.x private network address. - If it's a remote MongoDB instance, confirm:
- The remote server's firewall allows inbound traffic on port 27011 from your Windows 10 machine's IP.
- Your Windows Defender Firewall allows outbound traffic to that port and IP.
- Is this the correct IP/port for your MongoDB instance? If it's a local instance, you should be using
Test Port Connectivity
Use PowerShell to test if your machine can reach the target IP and port. Run this command:Test-NetConnection 10.237.141.117 -Port 27011If the result shows "TcpTestSucceeded: False", that confirms a network-level block—either the port isn't open, the MongoDB instance isn't listening on it, or a firewall is blocking the connection.
Check MongoDB's Listening Port & Bind IP
Open your MongoDB configuration file (usuallymongod.cfginC:\Program Files\MongoDB\Server\<version>\bin):- Look for the
net.portsetting—ensure it matches the port in your connection string (27011). The default port is 27017, so if you didn't change it, you might have a typo in your code. - Check the
net.bindIpsetting. If connecting remotely, set it to0.0.0.0(allow all IPs) or the server's specific IP. For local connections,127.0.0.1works, just make sure your connection string uses that IP.
- Look for the
Temporarily Disable Firewall for Testing
As a quick diagnostic step, temporarily turn off Windows Defender Firewall (go to Control Panel > System and Security > Windows Defender Firewall > Turn Windows Defender Firewall on or off). If your app connects successfully after this, add a permanent firewall rule to allow traffic to/from your MongoDB port.
内容的提问来源于stack exchange,提问作者Akhil Kintali

