Software⏱️ 2 min read📅 2026-05-31

How to Fix: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused

MongoDB connection refused error on Ubuntu

Quick Answer: Check if MongoDB is running and enable the service to start automatically on boot.

The error message 'Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused' typically indicates that the MongoDB server is not running or not listening on the specified port. This issue can occur due to various reasons such as the MongoDB service being stopped or not started, incorrect configuration, or a firewall blocking the connection.

🔍 Why This Happens

  • The MongoDB server may not be running or not listening on the specified port.

✅ Best Solutions to Fix It

Method 1: Start MongoDB Service

  1. Step 1: Check if the MongoDB service is running. You can do this by typing `sudo service mongodb status` in the terminal.

Method 2: Start MongoDB Manually

  1. Step 1: Navigate to the MongoDB data directory by typing `cd /var/lib/mongodb` in the terminal.

💡 Conclusion

To resolve this issue, you can try starting the MongoDB service or manually starting it. Additionally, ensure that the MongoDB configuration file is correct and the firewall settings are not blocking the connection.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions