localhost:27017: MongoDB connection fixes
Port 27017 is MongoDB’s default port. Connect with mongosh and fix ECONNREFUSED and timeouts.
Not a web pagePort 27017 belongs to MongoDB. Use mongosh or your app, not a browser.
localhost:27017 is where a local MongoDB server listens. It speaks the MongoDB protocol, so use mongosh, Compass or your app instead of a browser.
What runs on localhost:27017
- MongoDB servers (default port 27017)
- Docker containers started with
-p 27017:27017 - MongoDB Community on Windows, macOS (Homebrew) and Linux
Commands to start and test port 27017
mongosh "mongodb://127.0.0.1:27017"sudo systemctl start mongodbrew services start mongodb-communitydocker run -p 27017:27017 mongo:7Find what is using port 27017
Run these in a terminal on your computer. Nothing is sent to this site.
If localhost:27017 will not open
- ECONNREFUSED 127.0.0.1:27017
- mongod is not running. Start the service, then try again.
- It works with 127.0.0.1 but not localhost
- Newer Node versions can resolve localhost to IPv6 (::1) while MongoDB listens on IPv4. Use 127.0.0.1 in the connection string.
- Server selection timed out
- The app cannot reach the server. Check the port, the connection string and firewall rules.
- Port in use
- Another mongod is running. Find it with the tool below.
Other ports like 27017
| Port | Usually used by |
|---|---|
| localhost:3306 | MySQL, MariaDB |
| localhost:5432 | PostgreSQL |
| localhost:6379 | Redis |
| localhost:11211 | Memcached |
| localhost:1433 | Microsoft SQL Server |
| localhost:5984 | CouchDB |
| localhost:8983 | Apache Solr |
Questions about localhost:27017
- What is port 27017?
- The default port of MongoDB.
- Is MongoDB reachable from other computers by default?
- No. It listens on 127.0.0.1 by default. Change bindIp only if you also set up access control.
- Is localhost:27017 safe?
- Yes while it listens only on 127.0.0.1. If you open this port to a network, use a strong password, allow only trusted addresses in the firewall, and encrypt the connection. Do not expose a database port to the internet.
- Can I use a different port instead of 27017?
- Yes. Pick a free port above 1024, set it in the program, and open that number instead. If other programs connect to this port, change it there as well.
- How do I check what is using port 27017?
- Use the port checker on this page. It shows the command for Windows, macOS and Linux and does not send anything to this site.
Free tools that help
- Common ports listSearch a list of common TCP and UDP port numbers: SSH 22, HTTP 80, HTTPS 443, MySQL 3306, PostgreSQL 5432 and more, with dev server ports.