Skip to main content

MongoDB

Connect your MongoDB databases to enable Tony (Database Engineer) to analyze queries, optimize performance, and monitor database health.

Supported Platforms

PlatformSupport
Self-hosted MongoDB4.x, 5.x, 6.x, 7.x
MongoDB AtlasAll versions

Setup

Select your MongoDB platform for specific connection instructions:
1

Connect as Admin

Connect to your MongoDB instance using the Mongo shell (mongosh) with administrative privileges.Replace <admin-user>, <admin-password>, and <your-host> with your credentials. The /admin database is required.
mongosh "mongodb://<admin-user>:<admin-password>@<your-host>:27017/admin"
2

Switch to Admin Database

Ensure you are on the admin database where users are created:
use admin
3

Create Read-Only User

Create a dedicated user for CloudThinker using standard MongoDB built-in roles:
db.createUser({
  user: "<cloudthinker_user>",
  pwd: "<secure-password>",
  roles: [
    { role: "readAnyDatabase", db: "admin" },
    { role: "clusterMonitor", db: "admin" }
  ]
})
The clusterMonitor role is recommended for performance metrics analysis.
4

Configure Network Access

Ensure CloudThinker can reach your database:
  • Add CloudThinker IPs to your firewall or security group.
  • Ensure MongoDB is bound to an accessible IP address in mongod.conf.
5

Get Connection String

Your connection string will follow this format:
mongodb://<cloudthinker_user>:<secure-password>@<your-host>:27017/admin?tls=true&appName=CloudThinker
Note: Include tls=true if your deployment enforces TLS encryption in transit.

Add Connection in CloudThinker

Back in the CloudThinker App, navigate to Connections → MongoDB, add your customized Connection String, and finish.

Required Permissions

To get the most out of Tony’s analysis, the following standard MongoDB built-in roles are recommended:
  • readAnyDatabase: Required to analyze queries and index usage across your collections.
  • clusterMonitor: Recommended. Provides access to serverStatus, replSetGetStatus, and other diagnostic commands for performance metrics without granting write access.

Agent Capabilities

Once connected, Tony can:
CapabilityDescription
Query AnalysisIdentify slow queries, analyze execution plans (explain())
Index RecommendationsFind missing indexes, identify unused indexes
Performance MetricsMonitor connections, memory usage, replication lag

Example Prompts

@tony analyze slow queries on production MongoDB
@tony recommend index optimizations for the users collection
@tony check replication lag on the secondary nodes

Connection Options

OptionDescriptionDefault
TLS/SSLRequire TLS for the connectiontrue
Read PreferenceWhich nodes to route read operations toprimary
Connection TimeoutSeconds to wait for connection10

Troubleshooting

  • Verify username and password are correct.
  • Ensure the user is created on the admin database, or append ?authSource=admin to your connection string.
  • If using Atlas, ensure the user was created with the correct privileges under Database Access.
  • Check if CloudThinker IPs are added to your Atlas Network Access list or your firewall.
  • For local MongoDB, ensure bindIp in mongod.conf is not set to only 127.0.0.1.

Security Best Practices

  • Strong passwords - Use complex, unique passwords for the database user.
  • TLS encryption - Always encrypt data in transit (tls=true).
  • Network restrictions - Restrict database access to CloudThinker IPs via firewalls or Atlas Network Access.
  • Minimal permissions - Never grant write or admin roles to the CloudThinker user.

Tony Agent

Database-focused optimization agent

PostgreSQL Connection

Setup instructions for PostgreSQL databases