MongoDB Authentication Failure: Missing authSource=admin, Database Scope Misconfigurations & SCRAM Credentials
Resolving authentication rejections caused by missing authSource parameters in URIs, role scope mismatches, and SCRAM-SHA-256 enforcement.
Operational Verification & Reliability Metadata
The error string is a symptom, not the root cause. Do not restart the server blindly. Run the diagnostic queries below to pinpoint the actual failure mode.
▸Symptom
Authentication fails despite correct password credentials:
MongoServerError: Authentication failed.
MongoSecurityException: UserNotFound: Could not find user "app_user" for db "prod"▸What You See in Production
Application startup crashes with authentication rejections. Credentials work in shell but fail in drivers.
▸Root Cause Matrix
| Probability | Root Cause | Description |
|---|---|---|
| %70 | Missing `authSource=admin` | User provisioned in admin DB, but driver searches target DB for credentials. |
| %20 | SCRAM Mechanism Mismatch | Legacy driver defaulting to SCRAM-SHA-1 against modern cluster. |
| %10 | Scope Authorization Gaps | User lacks readWrite privileges in destination database. |
▸EMERGENCY RUNBOOK (0-5 min)
# 1. Connect specifying authentication database
mongosh -u app_user -p --authenticationDatabase admin 10.0.0.5:27017/prod// 2. Inspect user roles
use admin;
db.getUser("app_user");▸PERMANENT BLUEPRINT
- 1Explicit `authSource`: Always mandate
?authSource=adminon connection strings. - 2Enforce SCRAM-SHA-256: Align driver versions to support modern authentication protocols.
▸Verification
mongosh -u app_user -p 'Password' --authenticationDatabase admin --eval "db.stats()" 10.0.0.5:27017/prodOther Database Error Triage Playbooks
Other battle-tested diagnostic guides for high-severity database errors.
MongoDB "not master" / NotWritablePrimary Fix
Troubleshooting MongoDB "not master" (legacy < 5.0) and NotWritablePrimary (code 10107 >= 5.0) during replica set failovers, connection string topology URIs, retryWrites, and oplog sizing.
MongoDB E11000: Duplicate Key Error Triage & Mitigation
Diagnosing E11000 errors caused by concurrent insert races, index verification, and implementing atomic upsert with $setOnInsert.
MongoDB MongoNetworkError & HostUnreachable Triage
Addressing driver network timeouts, topology change failovers, invalid SRV connection strings, and serverSelectionTimeoutMS tuning.