Connecting to MongoDB

Connect Agent M to your MongoDB database, whether it's a local instance, MongoDB Atlas, or a self-hosted server.

Prerequisites

  • A MongoDB instance (local, Atlas, or self-hosted)
  • Connection credentials (if authentication is enabled)

Connection String Format

MongoDB uses connection strings to specify how to connect to your database:

Standard Connection

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

MongoDB Atlas (SRV)

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

Connection Methods

1Local MongoDB

For a local MongoDB instance running on your machine:

mongodb://localhost:27017

If authentication is enabled, add your credentials:

mongodb://username:password@localhost:27017/mydb

2MongoDB Atlas

  1. Go to MongoDB Atlas
  2. Select your cluster and click Connect
  3. Choose Connect your application
  4. Copy the connection string
  5. Replace <password> with your database password
  6. Replace myFirstDatabase with your database name
mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/mydb?retryWrites=true&w=majority

3Self-Hosted MongoDB

For a MongoDB server hosted on your own infrastructure:

mongodb://username:password@your-server.com:27017/mydb

Connect in Agent M

  1. Open Agent M
  2. Create a new connection
  3. Select MongoDB as the database type
  4. Enter a name for your connection
  5. Paste your connection string
  6. Click Connect

Common Connection Parameters

ParameterDescription
authSourceSpecify the database used for authentication
retryWritesEnable retryable writes (true/false)
wWrite concern (majority, 0, 1, 2, etc.)
sslEnable SSL/TLS connection (true/false)

Troubleshooting

Authentication Failed

  • Verify username and password are correct
  • Check if the authentication database is specified correctly
  • Ensure URL-encoded special characters in password

Connection Timeout

  • Check if MongoDB is running
  • Verify firewall allows port 27017
  • For Atlas, check IP whitelist settings

Network Issues

  • Verify host address is correct
  • Check internet connection (for Atlas/cloud)

Additional Resources

Next Steps