Skip to content

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-audio

Best Practice: Environment Separation

EnvironmentDatabasePurpose
Developmentctrl-audio-devLocal testing, safe to reset
Stagingctrl-audio-stagingPre-production testing
Productionctrl-audioLive 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-audio

Pros: Free, no extra configuration Cons: Shared resources could impact production


MongoDB Atlas vs Azure Cosmos DB

MongoDB Atlas (Current)

AspectDetails
Free Tier512MB storage, shared cluster
Paid TiersM10+ ($57+/month) for dedicated
AdvantagesNative MongoDB, familiar API, excellent tooling
Best ForWhen you need full MongoDB feature set

Azure Cosmos DB (Alternative)

AspectDetails
Free Tier1000 RU/s, 25GB storage (per subscription)
ServerlessPay per request (~$0.25/million RU)
AdvantagesNative Azure integration, global distribution
MongoDB APISupports MongoDB wire protocol (with limitations)

Recommendation for Ctrl-Audio

Stick with MongoDB Atlas for now because:

  1. Already configured - Migration adds complexity without immediate benefit
  2. Full MongoDB compatibility - Cosmos DB's MongoDB API has some limitations
  3. Free tier works - Until you hit scaling limits
  4. 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=Cluster00

2. 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

PracticeStatusAction Needed
Separate DB credentials per environmentCreate separate Atlas users
Environment variables in CI/CD⚠️Verify Azure App Settings
Connection string encryptionUsing Atlas TLS
IP Allowlist⚠️Consider enabling in Atlas

Ctrl-Audio Platform Documentation