Meteor应用本地自定义部署启动时遇MongoError连接拒绝问题求助
Hey there, let's work through this Mongo connection issue you're hitting when launching your Meteor app with Node. That ECONNREFUSED error tells us your app can't reach the MongoDB instance at 192.168.100.2:9001—here's how to troubleshoot and fix it:
1. Verify MongoDB is Running & Listening on the Correct Port/IP
First, make sure MongoDB is actually up and configured to listen on 192.168.100.2:9001:
- Check if the port is being monitored with this command:
You should see an entry forss -tulpn | grep 9001mongodbound to192.168.100.2:9001. - If MongoDB isn't running, start it with your system's service manager (e.g.,
sudo systemctl start mongod). - If it's running but not on the right IP/port, edit your MongoDB config file (usually
/etc/mongod.conf):- Update the
portfield to9001 - Set
bindIpto192.168.100.2(or0.0.0.0to allow all IPs for testing) - Restart MongoDB:
sudo systemctl restart mongod
- Update the
2. Ensure Your Meteor App Uses the Correct MONGO_URL
Meteor relies on the MONGO_URL environment variable to connect to MongoDB. Double-check you're setting it properly when launching the app:
- Launch your app with the correct connection string (replace
your-db-namewith your actual database name):MONGO_URL="mongodb://192.168.100.2:9001/your-db-name" node main.js - If you're using a
settings.jsonfile, confirm the MongoDB configuration inside matches the IP/port of your running instance.
3. Test Network Connectivity Between Your App & MongoDB
Even if MongoDB is running, network issues might block the connection:
- Ping the MongoDB server from your app's machine to confirm basic connectivity:
ping 192.168.100.2 - Test if the port is accessible with
nc(netcat):
If this fails, check your firewall rules—you'll need to allow inbound traffic on port 9001 fornc -zv 192.168.100.2 9001192.168.100.2.
4. Check MongoDB Authentication (If Enabled)
If your MongoDB instance requires a username and password, make sure MONGO_URL includes the auth details:
MONGO_URL="mongodb://your-username:your-password@192.168.100.2:9001/your-db-name?authSource=admin" node main.js
Ensure the user has read/write permissions for your target database.
5. Try Localhost for Same-Machine Deployments
If MongoDB is running on the same machine as your Meteor app, sometimes using localhost instead of the internal IP can resolve binding issues:
MONGO_URL="mongodb://localhost:9001/your-db-name" node main.js
If this works, it means MongoDB is only listening on localhost—update its bindIp config to include 192.168.100.2 as mentioned earlier.
内容的提问来源于stack exchange,提问作者StormTrooper

