MongoDB Connection String Checker and Builder

Find what’s wrong with a MongoDB URI, from unencoded passwords to SRV ports, or build a correct one for Atlas or a local server.

Ready-to-use .env and Mongoose code
Runs in your browser. Your connection string and password are never sent anywhere.

How to use the connection string checker

  1. Paste your connection string, or a whole MONGODB_URI=… line from your .env file.
  2. Read the list of problems. Red items stop the connection; amber items are worth fixing.
  3. Copy the corrected string and the ready-made Mongoose code from the right-hand side.

Switch to Build a string to create a new one from a form. Passwords with special characters are encoded for you.

Everything runs in your browser, so your password is never sent anywhere. Even so, if you have shared a production password in a chat, ticket or screenshot, change it in Atlas.

The mistakes this tool catches

Problem What you see Fix
Password contains @ : / ? # Authentication errors or “URI malformed” Percent-encode it, for example @ becomes %40
Placeholder left in, such as <db_password> Authentication failed Replace it, including the angle brackets
Port number on mongodb+srv:// Error that SRV URIs cannot have a port Remove :27017
Several hosts on mongodb+srv:// Parse error Use one host, or switch to mongodb://
localhost on Node.js 17 or newer ECONNREFUSED ::1:27017 Use 127.0.0.1
No database name Data lands in a database called test Add /myapp before the ?
Misspelled options Option silently ignored or rejected Fix the spelling, such as retryWrites

Anatomy of a connection string

mongodb+srv://appUser:s3cret%40pass@cluster0.abcde.mongodb.net/shop?retryWrites=true&w=majority
└─scheme──┘   └─user─┘ └─password──┘ └──────────host──────────┘ └db┘ └──────────options──────────┘

The mongodb+srv:// scheme looks up the cluster’s servers through DNS, which is why it takes one host name and no port. The plain mongodb:// scheme lists every host and port yourself.

Still getting ECONNREFUSED or a server selection timeout? Read the full fix guide for MongooseServerSelectionError.

Frequently asked questions

How do I put special characters in a MongoDB password?

Percent-encode them: @ is %40, : is %3A, / is %2F, # is %23 and % is %25. In code, use encodeURIComponent(password) when you build the string.

What is the difference between mongodb:// and mongodb+srv://?

mongodb+srv:// takes one host name and finds the cluster members through a DNS SRV record. It is what MongoDB Atlas gives you. mongodb:// lists hosts and ports directly and is common for local and self-hosted servers.

When do I need authSource=admin?

When your user was created in the admin database but your connection string names a different database. Atlas users don’t usually need it.

logo

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome content in your inbox.

We don’t spam! Read our privacy policy for more info.

More free tools