mongodb
auth_error
ai_generated
true
MongoServerError: Authentication failed
ID: mongodb/authentication-failed
90%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7 | active | — | — | — |
Root Cause
MongoDB authentication failed. Wrong credentials, wrong auth database, or auth not enabled.
genericWorkarounds
-
92% success Specify the correct authentication database
mongosh 'mongodb://user:pass@host:27017/mydb?authSource=admin'
Sources: https://www.mongodb.com/docs/manual/
-
88% success Verify user exists in the correct database
use admin; db.getUsers() # check which database the user was created in
-
82% success Reset password if forgotten
Start mongod without --auth, connect locally, db.changeUserPassword('user', 'newpass')
Dead Ends
Common approaches that don't work:
-
Connect without credentials assuming auth is disabled
75% fail
MongoDB 7+ enables auth by default. Even local connections require authentication.
-
Use the admin database credentials for all databases
70% fail
Users are scoped to their auth database. Admin user must specify authSource=admin.