Database Environment Management
Current Situation
Your local development uses the same MongoDB Atlas database as production because the .env file contains the same connection string. This is why local shows different data than production - you're connected to the same ctrl-audio database.
MONGODB_URI=mongodb+srv://...@cluster00.yghwyuu.mongodb.net/ctrl-audioBest Practice: Environment Separation
Recommended Setup
| Environment | Database | Purpose |
|---|---|---|
| Development | ctrl-audio-dev | Local testing, safe to reset |
| Staging | ctrl-audio-staging | Pre-production testing |
| Production | ctrl-audio | Live user data |
Implementation Options
Option 1: Same Atlas Cluster, Different Databases (Simplest)
Use different database names in the connection string:
bash
# Local .env
MONGODB_URI=mongodb+srv://...@cluster00.yghwyuu.mongodb.net/ctrl-audio-dev
# Staging .env (Azure GitHub Actions secret)
MONGODB_URI=mongodb+srv://...@cluster00.yghwyuu.mongodb.net/ctrl-audio-staging
# Production .env (Azure app settings)
MONGODB_URI=mongodb+srv://...@cluster00.yghwyuu.mongodb.net/ctrl-audioPros: Free, no extra configuration Cons: Shared resources could impact production
MongoDB Atlas vs Azure Cosmos DB
MongoDB Atlas (Current)
| Aspect | Details |
|---|---|
| Free Tier | 512MB storage, shared cluster |
| Paid Tiers | M10+ ($57+/month) for dedicated |
| Advantages | Native MongoDB, familiar API, excellent tooling |
| Best For | When you need full MongoDB feature set |
Azure Cosmos DB (Alternative)
| Aspect | Details |
|---|---|
| Free Tier | 1000 RU/s, 25GB storage (per subscription) |
| Serverless | Pay per request (~$0.25/million RU) |
| Advantages | Native Azure integration, global distribution |
| MongoDB API | Supports MongoDB wire protocol (with limitations) |
Recommendation for Ctrl-Audio
Stick with MongoDB Atlas for now because:
- ✅ Already configured - Migration adds complexity without immediate benefit
- ✅ Full MongoDB compatibility - Cosmos DB's MongoDB API has some limitations
- ✅ Free tier works - Until you hit scaling limits
- ✅ Better for audio metadata - GridFS support for large files if needed
Consider Cosmos DB when:
- You need global distribution (multi-region replication)
- You want unified Azure billing
- Your Azure credits cover the cost
Quick Fix: Separate Dev Database
To immediately separate your local database from production:
1. Update Backend .env:
bash
# Change database name from 'ctrl-audio' to 'ctrl-audio-dev'
MONGODB_URI=mongodb+srv://alocoifindo_db_user:dGQypZKO28AA6WpT@cluster00.yghwyuu.mongodb.net/ctrl-audio-dev?retryWrites=true&w=majority&appName=Cluster002. Create Test User in Dev Database:
bash
# The backend will auto-create collections on first use
# Register a new test user via the API
curl -X POST http://localhost:8080/user/register \
-H "Content-Type: application/json" \
-d '{"email":"test@test.com","password":"Test1234","username":"Testeo"}'Security Best Practices
| Practice | Status | Action Needed |
|---|---|---|
| Separate DB credentials per environment | ❌ | Create separate Atlas users |
| Environment variables in CI/CD | ⚠️ | Verify Azure App Settings |
| Connection string encryption | ✅ | Using Atlas TLS |
| IP Allowlist | ⚠️ | Consider enabling in Atlas |