Home / Localhost / localhost:27017

localhost:27017: MongoDB connection fixes

Port 27017 is MongoDB’s default port. Connect with mongosh and fix ECONNREFUSED and timeouts.

A database client connects to localhost:27017, which is port 27017 on your computer, where MongoDB is running

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

Commands to start and test port 27017

Connect with mongosh
mongosh "mongodb://127.0.0.1:27017"
Start it (Linux)
sudo systemctl start mongod
Start it (macOS, Homebrew)
brew services start mongodb-community
Docker: run a test database
docker run -p 27017:27017 mongo:7

Find 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

PortUsually used by
localhost:3306MySQL, MariaDB
localhost:5432PostgreSQL
localhost:6379Redis
localhost:11211Memcached
localhost:1433Microsoft SQL Server
localhost:5984CouchDB
localhost:8983Apache 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.

Updated 2026-10-03

Free tools that help

Related pages