# MongoDB: MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"

**Code:** `MongoParseError` · **Category:** MongoDB · **Seen on:** MongoDB

The connection string is missing, malformed, or the environment variable holding it is undefined.

## 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

1. Log whether the env var is set (not its value)
2. Remove quotes/spaces
3. URL-encode credentials

## Detailed fix by platform

### JavaScript

1. 

```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

1. **Env** — Variable loaded?
2. **Format** — Scheme and characters

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/mongodb/mongoparseerror-invalid-scheme)
