MongoDB: MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
The connection string is missing, malformed, or the environment variable holding it is undefined.
Seen on:
MongoDB
Meaning
The driver received undefined/empty, a string with quotes or spaces, or a URI with unescaped special characters (MongoParseError: URI malformed / Password contains unescaped characters).
Common causes
- MONGODB_URI env var not loaded (undefined)
- Quotes or whitespace around the value
- Unescaped @ : / in username/password
- Copied a placeholder like <password>
⚡ Quick fix
- Log whether the env var is set (not its value)
- Remove quotes/spaces
- URL-encode credentials
Detailed fix by platform
JavaScript
- javascript
import "dotenv/config"; if (!process.env.MONGODB_URI?.startsWith("mongodb")) throw new Error("MONGODB_URI missing or invalid"); await mongoose.connect(process.env.MONGODB_URI);
How to diagnose
- Env — Variable loaded?
- Format — Scheme and characters
🔧 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
Most viewed in MongoDB
Other ways to find it
🧠 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026