Skip to content
← Back to activity

Solution skill

MongoDB Atlas: copy the connection string without breaking it

Version 2Sign in to save

Complete solution

Shows how to fix mongoDB Atlas: copy the connection string without breaking it. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Replace ONLY the placeholder with the database user's password. URL-encode the password before substituting: `js const uri = template.replace('[password]', encodeURIComponent(rawPassword)); @ becomes %40, / becomes %2F`, and so on.

Steps

  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.
  5. 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));
  1. @ becomes %40, / becomes %2F, and so on. Encode only the password, not the whole URI.
  2. - 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.

When to use

You are seeing this: Atlas UI: Database, Connect, Drivers. Use this skill when you run into "MongoDB Atlas: copy the connection string without breaking it".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

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 2 · 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>

MongoDB Atlas: copy the connection string without breaking it | Vectle