Connection string
CampusBite reads the MongoDB connection string from environment variables:backend/src/config/db.js
MONGODB_URI or DATABASE_URL. If both are set, MONGODB_URI takes precedence.
MongoDB Atlas (cloud)
Create a free cluster
Sign up at mongodb.com/cloud/atlas and create a free M0 cluster.
Configure network access
Add your IP address to the IP Access List:
- Go to Network Access → Add IP Address
- For development: Click Allow Access from Anywhere (0.0.0.0/0)
- For production: Add your server’s IP or use VPC peering
Create a database user
Go to Database Access and create a new user with read/write permissions to your database.
Get the connection string
Click Connect → Connect your application and copy the connection string:Replace
username and password with your database credentials.DNS resolution issues
If you encounter SRV DNS lookup errors (common in restrictive networks):Self-hosted MongoDB
For local development or self-hosted production:Install MongoDB
Follow the official installation guide for your platform.
Database initialization
CampusBite automatically connects to MongoDB on startup:backend/src/config/db.js
- Connection timeout: 5 seconds
- Database name: Extracted from connection string or set via
MONGODB_DB_NAME - Error guidance: Provides specific troubleshooting steps for SRV DNS failures
Specifying database name
You can specify the database name in two ways:- In connection string
- Via environment variable
MONGODB_DB_NAME takes precedence.
Connection validation
The server performs preflight checks at startup:backend/src/config/preflight.js
MONGODB_URI is missing or empty, the server will exit with:
Troubleshooting
Connection refused
Authentication failed
SRV DNS lookup failed
Database timeout
- Check network connectivity to your MongoDB host
- Verify firewall rules allow outbound connections on port 27017
- For Atlas, ensure your IP is whitelisted in Network Access
Collections
CampusBite uses the following MongoDB collections (created automatically via Mongoose schemas):users- User accounts (students, vendors, admins)stores- Vendor stores and menusmenuitems- Menu items for each storeorders- Order history and statusnotifications- Real-time notifications