Connections

Connection Strings

Understanding MongoDB connection string formats and options.

Overview

MongoDB connection strings (URIs) provide a standardized way to specify connection parameters. Sutido supports both the standard format and the DNS seed list format (mongodb+srv).

Standard Connection String Format

mongodb://[username:password@]host[:port][/database][?options]

Examples

# Local connection (default port)
mongodb://localhost:27017

# With authentication
mongodb://myuser:mypassword@localhost:27017/mydb

# With auth database specified
mongodb://myuser:mypassword@localhost:27017/mydb?authSource=admin

# Multiple hosts (replica set)
mongodb://host1:27017,host2:27017,host3:27017/?replicaSet=myRS

DNS Seed List Format (SRV)

The mongodb+srv format is commonly used with MongoDB Atlas and other cloud services. It uses DNS SRV records to discover hosts:

mongodb+srv://username:password@cluster.mongodb.net/database

Connection String Components

Component Description Example
Protocol mongodb:// or mongodb+srv:// mongodb://
Username Authentication username (URL encoded) myuser
Password Authentication password (URL encoded) p%40ssword
Host Server hostname or IP localhost
Port Server port (default: 27017) 27017
Database Default database to connect to mydb
Options Query string parameters ?authSource=admin

Common Connection Options

Authentication Options

Option Description
authSource Database containing user credentials
authMechanism Authentication method (SCRAM-SHA-256, SCRAM-SHA-1)

Replica Set Options

Option Description
replicaSet Name of the replica set
readPreference How to route read operations (primary, secondary, etc.)

Connection Pool Options

Option Description
maxPoolSize Maximum number of connections in the pool
minPoolSize Minimum number of connections in the pool
connectTimeoutMS Connection timeout in milliseconds
socketTimeoutMS Socket timeout in milliseconds

Special Characters in Passwords

If your password contains special characters, they must be URL-encoded:

Character Encoded
@%40
:%3A
/%2F
%%25
#%23
?%3F
# Password is "p@ss:word"
mongodb://user:p%40ss%3Aword@localhost:27017/mydb

Tip: When pasting a connection string into Sutido, special characters are handled automatically.

Building URIs in Sutido

Sutido can build connection strings from manual configuration. After configuring your connection settings, you can view the equivalent URI in the connection details.

Next Steps

Learn about connecting through SSH tunnels.