localhost:27017
Port 27017 is MongoDB — the popular NoSQL document database. Store JSON-like documents, scale horizontally, query with powerful aggregations. MERN stack developers live on this port.
Connect to MongoDB
MongoDB Shell (mongosh)
# Connect locally
mongosh
# Or specify connection
mongosh "mongodb://localhost:27017"
# Connect to specific database
mongosh "mongodb://localhost:27017/mydb"
# With authentication
mongosh "mongodb://user:pass@localhost:27017/mydb"
Connection Strings
# Standard URI
mongodb://localhost:27017/mydb
# Node.js (Mongoose)
mongoose.connect('mongodb://localhost:27017/mydb');
# Python (PyMongo)
client = MongoClient('mongodb://localhost:27017/')
# PHP
$client = new MongoDB\Client("mongodb://localhost:27017");
Check if MongoDB is Running
# Linux
sudo systemctl status mongod
# Mac (Homebrew)
brew services list | grep mongodb
# Test connection
mongosh --eval "db.runCommand({ping:1})"
Common Errors
| Error | Solution |
|---|---|
| Connection refused | MongoDB not running. Start mongod service. |
| Authentication failed | Check username/password and authSource |
| Network timeout | Check firewall, verify bindIp setting |
Start MongoDB
# Linux
sudo systemctl start mongod
# Mac
brew services start mongodb-community
# Docker
docker run -d -p 27017:27017 mongo
# Manual
mongod --dbpath /data/db
MongoDB Compass
GUI tool for MongoDB. Connect using:
mongodb://localhost:27017