mongodb auth_error ai_generated true

MongoServerError: Authentication failed

ID: mongodb/authentication-failed

Also available as: JSON · Markdown
90%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7 active

Root Cause

MongoDB authentication failed. Wrong credentials, wrong auth database, or auth not enabled.

generic

Workarounds

  1. 92% success Specify the correct authentication database
    mongosh 'mongodb://user:pass@host:27017/mydb?authSource=admin'

    Sources: https://www.mongodb.com/docs/manual/

  2. 88% success Verify user exists in the correct database
    use admin; db.getUsers()  # check which database the user was created in
  3. 82% success Reset password if forgotten
    Start mongod without --auth, connect locally, db.changeUserPassword('user', 'newpass')

Dead Ends

Common approaches that don't work:

  1. Connect without credentials assuming auth is disabled 75% fail

    MongoDB 7+ enables auth by default. Even local connections require authentication.

  2. Use the admin database credentials for all databases 70% fail

    Users are scoped to their auth database. Admin user must specify authSource=admin.