MongoDB Error 18 AuthenticationFailed (Wrong authSource)

User was created in `admin` database but connection string omitted `?authSource=admin`.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: MongoDB Error 18 AuthenticationFailed (Wrong authSource) Platform: MongoDB
Common Root Causes:
  • User was created in `admin` database but connection string omitted `?authSource=admin`.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Explicitly specify `authSource` matching the database where the user was created.
Safe Diagnostic Command:
mongosh "mongodb://user:pass@127.0.0.1:27017/appdb?authSource=admin"
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

User was created in `admin` database but connection string omitted `?authSource=admin`. Recommended diagnostic: `mongosh "mongodb://user:pass@127.0.0.1:27017/appdb?authSource=admin"`. Remediation: Explicitly specify `authSource` matching the database where the user was created.

Worked Examples

  • Run `mongosh "mongodb://user:pass@127.0.0.1:27017/appdb?authSource=admin"` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-mongodb-authentication-failed-18 · Independently verified: 2026-11-25

Related Resources