Local MongoDB Development¶
Run a local MongoDB container seeded from an Atlas scheduled backup, so you can develop against real data without connecting to the production database.
Prerequisites¶
- Docker installed and running
- An Atlas scheduled backup
.tar.gzfile downloaded to your machine
Downloading an Atlas Backup¶
- Go to MongoDB Atlas → Cluster0 → Backup → Snapshots
- Select a scheduled snapshot and click Download
- Save the
.tar.gzfile to a local directory, e.g.:
mkdir -p ~/.syrf/backups
# Move your downloaded file
mv ~/Downloads/Cluster0-snapshot-*.tar.gz ~/.syrf/backups/
Starting MongoDB with Seed Data¶
Set the SYRF_ATLAS_BACKUP environment variable and start the container:
SYRF_ATLAS_BACKUP=~/.syrf/backups/Cluster0-snapshot-2026-03-07.tar.gz \
docker compose -f docker-compose.dev.yml up -d mongodb
On first startup, the container will:
- Extract the Atlas backup
.tar.gz(raw WiredTiger data files) - Start a temporary
mongodon the extracted data - Rename the
syrftestdatabase tosyrf_local(matchingappsettings.Development.json) - Drop other databases from the backup (e.g.
syrfdev) - Write a
.syrf-seededmarker so subsequent restarts skip seeding - Start
mongodnormally on port 27017
The API and Project Management services are already configured to connect to localhost:27017 / syrf_local in development mode — no config changes needed.
Starting Without Seed Data¶
If you don't need production data (e.g. for testing new features from scratch):
Without SYRF_ATLAS_BACKUP, the container starts with an empty syrf_local database.
Re-seeding with a New Backup¶
To replace the database with a newer Atlas backup:
# Remove the existing container and its data volume
docker compose -f docker-compose.dev.yml down -v
# Start with the new backup
SYRF_ATLAS_BACKUP=~/.syrf/backups/newer-backup.tar.gz \
docker compose -f docker-compose.dev.yml up -d mongodb
The -v flag removes the syrf-mongo-data volume, which triggers a fresh seed on next startup.
Troubleshooting¶
Check seed progress¶
The seed script logs each phase with [syrf-seed] prefixes.
Seed failed or data looks wrong¶
# Reset completely
docker compose -f docker-compose.dev.yml down -v
# Try again
SYRF_ATLAS_BACKUP=~/.syrf/backups/backup.tar.gz \
docker compose -f docker-compose.dev.yml up -d mongodb
Connect to the local database¶
# Via mongosh
docker exec -it syrf-mongodb mongosh syrf_local
# List collections
docker exec -it syrf-mongodb mongosh syrf_local --eval "db.getCollectionNames()"
CSUUID (GUID) format¶
All IDs in the database use BinData subtype 3 (CSUUID / C# Legacy). When querying manually:
// Use CSUUID(), not UUID()
db.pmProject.find({ _id: CSUUID("550e8400-e29b-41d4-a716-446655440000") })
See MongoDB Reference for details.
How It Works¶
The seed mechanism uses the fact that Atlas scheduled backups contain raw WiredTiger data directory files (not mongodump BSON). The script:
- Extracts the
.tar.gzinto a temporary directory - Locates the WiredTiger data files (handling nested directory structures)
- Starts a temporary
mongodon port 27018 pointing at the extracted data - Uses
renameCollectionadmin commands to renamesyrftest→syrf_local - Copies the processed data into the container's
/data/db - Writes a marker file to prevent re-seeding on restart
This approach is faster than mongodump/mongorestore because it works directly with the storage engine files.
Related¶
- MongoDB Reference — database architecture, collections, CSUUID format
- MongoDB Testing Strategy — planned environment isolation