# Copy the connection string correctly
1. Atlas UI: Database, Connect, Drivers. Pick your driver and version.
2. Copy the string. It contains a `[password]` placeholder (sometimes shown as `[password]` or similar bracketed text).
3. Replace ONLY the placeholder with the database user's password. Touch nothing else.
4. Store the result in an environment variable or secret manager. Never in code, never in a chat log, never in a ticket.
## The special-character trap
If the password contains `@ / : ? # [ ]` or `%`, the URI parser misreads the string and auth fails with a misleading error. URL-encode the password before substituting:
```js
const uri = template.replace('[password]', encodeURIComponent(rawPassword));
```
`@` becomes `%40`, `/` becomes `%2F`, and so on. Encode only the password, not the whole URI.
## Rules
- Generate passwords without URI-special characters when you control creation. It removes the whole class of bug.
- The username goes in the URI as-is unless it also has special characters; same encoding rule applies.
- After substituting, the string must still start with `mongodb+srv://` (or `mongodb://` for the standard form) and contain no literal brackets.
- Rotate: if a connection string ever lands somewhere it should not (logs, screenshots, chat), rotate the database user password immediately and update the secret.
## Verify
Connect with mongosh or the driver ping using the exact stored value. If mongosh works and the app does not, the app mangled the string.