MongoDB Connection String Generator

Generate connection strings for MongoDB in any format. Node.js, Python, Java, Go, .NET, and more.

Client-side only — nothing leaves your browser

mongodb://localhost:27017/mydb

What is a MongoDB Connection String?

A MongoDB connection string (URI) contains all the information needed to connect to a MongoDB deployment: host address, port, database name, credentials, and options like TLS, replica set, and read preference. Most MongoDB drivers across all languages accept the standard URI format.

Connection Schemes

  • mongodb:// — Standard connection format with explicit host and port
  • mongodb+srv:// — DNS seedlist format, used by MongoDB Atlas and clusters with SRV records (no port needed)

Quick Reference

FormatExample Pattern
Standard URImongodb://user:pass@host:27017/mydb?authSource=admin
SRV URI (Atlas)mongodb+srv://user:[email protected]/mydb
With Replica Setmongodb://user:pass@host:27017/mydb?replicaSet=rs0
With TLSmongodb://user:pass@host:27017/mydb?tls=true&authSource=admin
No Auth (local)mongodb://localhost:27017/mydb
Read Preferencemongodb://user:pass@host:27017/mydb?readPreference=secondaryPreferred
Full Optionsmongodb+srv://user:pass@host/mydb?authSource=admin&tls=true&replicaSet=rs0
Dockermongodb://root:pass@mongo:27017/mydb?authSource=admin

Frequently Asked Questions

What is the difference between mongodb:// and mongodb+srv:// connection strings?
The mongodb:// scheme is the standard connection format where you specify hosts and ports directly (e.g., mongodb://host:27017). The mongodb+srv:// scheme uses DNS SRV records to discover all nodes in a cluster automatically, so you only provide a hostname without a port. MongoDB Atlas uses mongodb+srv:// by default because it simplifies connection strings for replica sets and sharded clusters.
What is authSource in a MongoDB connection string?
The authSource parameter specifies which database MongoDB should authenticate your credentials against. By default this is the 'admin' database, but it can be any database where the user was created. If your user was created in a specific database (e.g., 'myapp'), set authSource=myapp. When using MongoDB Atlas, authSource is usually 'admin' regardless of which database you're connecting to.
How do I escape special characters in a MongoDB connection string password?
Special characters in MongoDB passwords must be percent-encoded (URL-encoded) when used in a connection URI. For example, @ becomes %40, : becomes %3A, / becomes %2F, and # becomes %23. This is required because these characters have special meaning in URIs. Our generator handles this encoding automatically. If building strings manually, use your language's URL-encoding function (e.g., encodeURIComponent in JavaScript, urllib.parse.quote in Python).
How do I connect to MongoDB in Docker?
From the host machine, use mongodb://localhost:27017 if you mapped the port with -p 27017:27017. From another container in the same Docker network, use the container name as the host: mongodb://mongo-container:27017/mydb. In Docker Compose, use the service name (e.g., mongodb://mongo:27017/mydb). Add username and password if MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD are set.
How do I find my MongoDB Atlas connection string?
In MongoDB Atlas, go to your cluster's dashboard, click 'Connect', then choose your connection method (e.g., 'Drivers'). Atlas will show a connection string template like mongodb+srv://username:<password>@cluster0.xxxxx.mongodb.net/mydb?retryWrites=true&w=majority. Replace <password> with your database user's password and 'mydb' with your database name. Make sure your IP address is whitelisted in Network Access.
MongoDB

Need a MongoDB GUI Client?

1bench is a modern database client for MongoDB and 20+ other databases. Query, browse, and manage your data visually.

Learn More