The backend is returning a 503 error because it cannot connect to MongoDB Atlas. This is a common issue when deploying to Vercel.
- MongoDB Atlas IP Whitelist - Vercel uses dynamic IPs that need to be whitelisted
- Connection String Issues - Incorrect or expired credentials
- Network Access Settings - MongoDB Atlas firewall blocking connections
- Serverless Cold Starts - Connection timing out on first request
- Go to MongoDB Atlas
- Select your cluster: Sample-Data
- Click on Network Access in the left sidebar
- Click Add IP Address
- Select "Allow Access from Anywhere" (0.0.0.0/0)
- This is necessary for Vercel since it uses dynamic IPs
- Click Confirm
Important: This is the most common cause of the 503 error!
- In MongoDB Atlas, go to Database Access
- Verify user:
jenilrupapara340_db_user - If the user doesn't exist or password is wrong:
- Click Add New Database User
- Username:
jenilrupapara340_db_user - Password:
gPaASk6ZOa4Wa44L(or create a new one) - Database User Privileges: Read and write to any database
- Click Add User
If you created a new user or changed the password, update the connection string:
Current connection string in code:
mongodb+srv://jenilrupapara340_db_user:gPaASk6ZOa4Wa44L@sample-data.vyal4lo.mongodb.net/bavadiya-realty?retryWrites=true&w=majority
To get the correct connection string:
- In MongoDB Atlas, click Connect on your cluster
- Choose Connect your application
- Copy the connection string
- Replace
<password>with your actual password - Replace
<dbname>withbavadiya-realty
- Go to Vercel Dashboard
- Select your backend project: bavadiya-realty-backend
- Go to Settings → Environment Variables
- Add or update:
MONGO_URI=mongodb+srv://jenilrupapara340_db_user:gPaASk6ZOa4Wa44L@sample-data.vyal4lo.mongodb.net/bavadiya-realty?retryWrites=true&w=majority - Make sure it's enabled for Production, Preview, and Development
- Click Save
After making changes to environment variables:
cd backend
vercel --prodOr trigger a redeploy from Vercel Dashboard:
- Go to Deployments
- Click the three dots on the latest deployment
- Click Redeploy
curl https://bavadiya-realty-backend.vercel.app/api/healthExpected Response (Success):
{
"status": "healthy",
"timestamp": "2025-11-19T13:11:00.000Z",
"database": {
"state": "connected",
"stateCode": 1,
"userCount": 1
},
"environment": "production"
}If Still Failing:
{
"status": "unhealthy",
"timestamp": "2025-11-19T13:11:00.000Z",
"database": {
"state": "disconnected",
"stateCode": 0
},
"environment": "production"
}curl -X POST https://bavadiya-realty-backend.vercel.app/api/login \
-H "Content-Type: application/json" \
-d '{"username":"DharmeshBavadiya","password":"BavadiyaRealtyAdmin!2024"}'Solution: Add 0.0.0.0/0 to MongoDB Atlas Network Access (Step 1)
Solution: Verify database user credentials (Step 2)
Solution:
- Check Vercel logs:
vercel logs bavadiya-realty-backend --prod - Verify MONGO_URI environment variable is set correctly
- Ensure MongoDB cluster is not paused (check Atlas dashboard)
Solution:
- Verify connection string format
- Check if MongoDB cluster is running (not paused)
- Verify network access settings
To see detailed error messages:
# Install Vercel CLI if not already installed
npm i -g vercel
# Login to Vercel
vercel login
# View logs
vercel logs bavadiya-realty-backend --prodLook for messages like:
✅ MongoDB connected(Success)❌ MongoDB connection error(Failure - check the error message)
Make sure your cluster is not paused:
- Go to MongoDB Atlas Dashboard
- Check if cluster shows "Paused"
- If paused, click Resume button
To test if the connection string works:
cd backend
node -e "
const mongoose = require('mongoose');
mongoose.connect('mongodb+srv://jenilrupapara340_db_user:gPaASk6ZOa4Wa44L@sample-data.vyal4lo.mongodb.net/bavadiya-realty?retryWrites=true&w=majority')
.then(() => { console.log('✅ Connected'); process.exit(0); })
.catch(err => { console.error('❌ Error:', err.message); process.exit(1); });
"- MongoDB Atlas Network Access allows 0.0.0.0/0
- Database user exists with correct credentials
- MONGO_URI environment variable is set in Vercel
- MongoDB cluster is not paused
- Backend has been redeployed after env variable changes
- Health endpoint returns "connected" status
If you've completed all steps and it's still not working:
- Check MongoDB Atlas Status Page: https://status.cloud.mongodb.com/
- Verify Vercel Status: https://www.vercel-status.com/
- Create a new MongoDB cluster and update the connection string
- Contact Support:
- MongoDB Atlas Support: https://support.mongodb.com/
- Vercel Support: https://vercel.com/support
You'll know it's working when:
- Health endpoint returns
"state": "connected" - Login endpoint returns a JWT token
- Frontend can successfully log in
- No 503 errors in browser console
The following improvements were made to handle serverless connections better:
- Connection Caching - Reuses existing connections in serverless environment
- Automatic Reconnection - Attempts to reconnect if connection is lost
- Better Error Messages - Detailed logging for debugging
- Health Check Endpoint - Easy way to verify connection status
- Optimized Timeouts - Faster failure detection and retry logic
Make sure these are set in Vercel:
MONGO_URI=mongodb+srv://jenilrupapara340_db_user:gPaASk6ZOa4Wa44L@sample-data.vyal4lo.mongodb.net/bavadiya-realty?retryWrites=true&w=majority
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production_123456789
NODE_ENV=production
DEFAULT_ADMIN_USERNAME=DharmeshBavadiya
DEFAULT_ADMIN_PASSWORD=BavadiyaRealtyAdmin!2024
DEFAULT_ADMIN_EMAIL=admin@bavadiyarealty.com
BCRYPT_ROUNDS=12
JWT_EXPIRES_IN=24h
ALLOWED_ORIGINS=https://bavadiyarealty.vercel.app
PORT=3000Once the connection is working:
- Test login from frontend
- Verify data operations (create, read, update, delete)
- Monitor Vercel logs for any issues
- Consider setting up monitoring/alerts for database connectivity