MongoParseError: URI malformed, cannot be parsed / Password contains unescaped characters
The connection string contains characters in the user or password that must be percent-encoded.
MongoParseError: URI malformed, cannot be parsedPassword contains unescaped charactersMongoParseError: Username contains unescaped charactersMongoAPIError: URI must include hostname, domain name, and tldURI malformed MongoDB password special characters Meaning
Characters : / ? # [ ] @ % in credentials must be URL-encoded (@ → %40, / → %2F). Build the URI with encodeURIComponent. The same applies to database names with special characters. Atlas users with passwords generated using symbols hit this frequently.
Common causes
@or/inside the password- Unencoded
#,?,% - Copy-pasted connection string with
<password>placeholder left in - Spaces in credentials
- Missing
mongodb://prefix
⚡ Quick fix
encodeURIComponent(password)when building the URI- Replace
<password>placeholder with the real encoded password - Use the driver's options object (
auth: {username, password})
Detailed fix by platform
Node.js
const uri = \mongodb+srv://${encodeURIComponent(u)}:${encodeURIComponent(p)}@cluster0.abcde.mongodb.net/db\;
How to diagnose
- Password — Special chars encoded?
- Placeholder — Replaced?
- Scheme — Correct?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Atlas: bad auth: Authentication failed MongoServerError: bad auth : Authentication failed. (Atlas user / special characters in password)
- BSONObj size is invalid / exceeds maximum document size (16MB) MongoServerError: BSONObj size: 17825792 (0x1100000) is invalid. Size must be between 0 and 16793600(16MB)
- Can't connect from another host (bindIp 127.0.0.1) MongoDB: connection refused / timed out from a remote host — mongod bindIp defaults to 127.0.0.1
Most viewed in MongoDB
- Document failed validation MongoDB: MongoServerError: Document failed validation (code 121)
- bad auth : Authentication failed MongoDB: MongoServerError: bad auth : Authentication failed (code 8000 / 18)
- StrictPopulateError: Cannot populate path because it is not in your schema Mongoose 6+: StrictPopulateError: Cannot populate path `author` because it is not in your schema
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026