MongoDB · error reference
MongoDB: Authentication failed (code 18)
MongoServerError: Authentication failed.
In MongoDB a user belongs to a database. If the connection string looks in the wrong one, a correct password still fails.
What the database is telling you
Error code 18 (AuthenticationFailed): the user name and password did not verify against the authentication database. MongoDB authenticates against the database named by authSource — or, when that is absent, the database in the URI's path. Users created in admin (the usual place) are not found when the path names an application database and authSource is not set.
Why it shows up in a migration
Migration tools take the database name from the URI path, which then doubles as the authentication database. That is the moment a URI that worked for an admin shell, which connected to admin, starts failing.
Common causes
- authSource is missing, so MongoDB looks for the user in the application database instead of admin.
- Special characters in the password (@ : / ? #) not percent-encoded in the URI.
- On Atlas, using the Atlas account password instead of the database user's password.
- The user exists on another cluster, or was created after a restore that did not include users.
How to fix it
- 1
Say where the user lives.
mongodb://app:secret@db.example.com:27017/shop?authSource=admin
- 2
Find which database holds the user (as an admin).
db.getSiblingDB("admin").system.users.find({ user: "app" }, { db: 1, user: 1 }) - 3
Percent-encode the password inside the URI.
// p@ss:word becomes p%40ss%3Aword
- 4
On Atlas, check the user under Database Access (not your login), and reset its password there.
What DBShifts does about it
Connection diagnosis classes this as "Authentication failed" and points at the user and password. For Atlas hosts (*.mongodb.net) DBShifts builds the mongodb+srv:// URI itself, so the SRV and TLS parts are not something to get wrong.
Connection diagnosis
Connecting a database?
Add the database to DBShifts and the connection is tested on the spot. If it fails, you get which of these errors it is and what to change — not the driver's raw message. Once it connects, browse it, migrate it, or let an AI agent read it through the gateway with sensitive columns masked.