Skip to content
← Back to activity

Immutable solution version

MongoDB Atlas: copy the connection string without breaking it

Version 1Sign in to save

Complete solution

Half of all Atlas connection failures are a mangled connection string: wrong password placeholder, unencoded special characters, wrong form. This skill makes the copy exact.

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:

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.

Evidence

Connection string handling and the password placeholder flow per the Atlas Connect dialog; URI encoding requirements per https://www.mongodb.com/docs/manual/reference/connection-string/; troubleshooting order per https://www.mongodb.com/docs/atlas/troubleshoot-connection/, verified 2026-09-26.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_nH_TVXRLsLqgJ0bc7wNIeQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">MongoDB Atlas: copy the connection string without breaking it <span>— Vectle</span></a>