# MongoDB Setup Guide

## Option 1: MongoDB Atlas (Recommended - No Installation Required)

1. **Go to [MongoDB Atlas](https://www.mongodb.com/atlas)**
2. **Create a free account**
3. **Create a new cluster** (free tier is sufficient)
4. **Set up database access:**
   - Create a database user with username and password
   - Remember these credentials
5. **Set up network access:**
   - Add your IP address or use `0.0.0.0/0` for all IPs
6. **Get your connection string:**
   - Click "Connect" on your cluster
   - Choose "Connect your application"
   - Copy the connection string
7. **Update your config.env:**
   ```env
   MONGO_URI=mongodb+srv://yourusername:yourpassword@yourcluster.mongodb.net/car-wash-app?retryWrites=true&w=majority
   ```

## Option 2: Local MongoDB Installation

### Windows:
1. **Download MongoDB Community Server** from [mongodb.com](https://www.mongodb.com/try/download/community)
2. **Install MongoDB** with default settings
3. **Start MongoDB service:**
   ```cmd
   net start MongoDB
   ```
4. **Or install MongoDB as a service:**
   ```cmd
   "C:\Program Files\MongoDB\Server\6.0\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\6.0\bin\mongod.cfg" --install
   ```

### macOS:
```bash
# Using Homebrew
brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb/brew/mongodb-community
```

### Linux (Ubuntu):
```bash
# Import MongoDB public GPG key
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -

# Create list file for MongoDB
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

# Update package database
sudo apt-get update

# Install MongoDB
sudo apt-get install -y mongodb-org

# Start MongoDB
sudo systemctl start mongod
sudo systemctl enable mongod
```

## Quick Test

After setting up MongoDB (either Atlas or local), test the connection:

```bash
cd server
node test-db.js
```

You should see:
```
✅ Database connection successful!
✅ Database write test successful!
```

## Troubleshooting

### If using local MongoDB:
- Make sure MongoDB service is running
- Check if port 27017 is available
- Try connecting with MongoDB Compass (GUI tool)

### If using MongoDB Atlas:
- Check your IP address is whitelisted
- Verify username and password are correct
- Ensure the cluster is active

### Common Issues:
1. **Connection timeout**: Check if MongoDB is running
2. **Authentication failed**: Verify credentials
3. **Network access denied**: Check IP whitelist (Atlas) or firewall (local) 