Did you mean to connect to: mongodb://localhost:27017?
Port 27017 is for MongoDB database connections. Use mongo shell or your application driver to connect.
sudo systemctl status mongod
(Linux)brew services list | grep mongodb
(Mac)tasklist | findstr mongod
(Windows)
mongo
(Legacy shell)mongosh
(New shell)mongo mongodb://localhost:27017/database
lsof -i :27017
(Mac/Linux)netstat -ano | findstr :27017
(Windows)
sudo systemctl start mongod
(Linux)brew services start mongodb-community
(Mac)net start MongoDB
(Windows)
Port 27017 is the default port for:
MongoDB server is not running or not accessible:
sudo systemctl start mongod
mongod --version
netstat -tlnp | grep 27017
sudo tail -f /var/log/mongodb/mongod.log
mongod --dbpath /data/db
Authentication error when connecting to MongoDB:
mongo --authenticationDatabase admin
use admin db.createUser({ user: "admin", pwd: "password", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] })
mongo -u admin -p password --authenticationDatabase admin
MongoDB data directory doesn't exist:
sudo mkdir -p /data/db
sudo chown -R mongodb:mongodb /data/db
mongod --dbpath /custom/path
Another process is using MongoDB's port:
lsof -i :27017
sudo systemctl stop mongod
sudo kill -9 PID
net: port: 27018
sudo systemctl restart mongod
Network connectivity issues with MongoDB:
bindIp: 127.0.0.1
telnet localhost 27017
bindIp: 0.0.0.0
ping localhost