Monitor and optimize your MongoDB databases
DB24x7 provides comprehensive monitoring for MongoDB databases, including query performance analysis, operation profiling, replica set monitoring, sharded cluster insights, and real-time metrics tracking.
Supported Versions
MongoDB 4.4+, 5.0+, 6.0+, 7.0+
Real-time Monitoring
Profiler-based insights
Query Analysis
Slow operation detection
Cloud Support
MongoDB Atlas, AWS DocumentDB
The MongoDB profiler is recommended for detailed query performance tracking. Configure it to capture slow operations.
Profile Slow Operations (Recommended)
// Profile operations slower than 100ms
db.setProfilingLevel(1, { slowms: 100 });
// Verify profiler status
db.getProfilingStatus();Profile All Operations (Development Only)
// Profile all operations (high overhead) db.setProfilingLevel(2);
Set Profiler for Specific Database
// Switch to target database
use your_database;
// Enable profiling
db.setProfilingLevel(1, { slowms: 100, sampleRate: 1.0 });Note
Profiling level 2 (all operations) has significant performance overhead. Use level 1 in production environments.
Create a dedicated user with minimal required roles for monitoring.
Create Monitoring User
// Connect to admin database
use admin;
// Create monitoring user
db.createUser({
user: "db24x7_monitor",
pwd: "your_secure_password",
roles: [
{ role: "clusterMonitor", db: "admin" },
{ role: "read", db: "admin" },
{ role: "read", db: "local" },
{ role: "read", db: "config" }
]
});Grant Database-Specific Read Access
// For each database you want to monitor
use your_database;
db.grantRolesToUser("db24x7_monitor", [
{ role: "read", db: "your_database" }
]);Verify User Permissions
use admin;
// Check user roles
db.getUser("db24x7_monitor");
// Test authentication
db.auth("db24x7_monitor", "your_secure_password");Built-in Monitoring Roles
clusterMonitor provides read-only access to monitoring tools and all databases. This is the minimum required role.
Use the following connection URI format to connect DB24x7 to your MongoDB database:
Standalone MongoDB
mongodb://db24x7_monitor:your_secure_password@hostname:27017/admin?authSource=admin
Replica Set
mongodb://db24x7_monitor:password@host1:27017,host2:27017,host3:27017/admin?replicaSet=myReplicaSet&authSource=admin
MongoDB Atlas
mongodb+srv://db24x7_monitor:password@cluster0.mongodb.net/admin?retryWrites=true&w=majority
With SSL/TLS
mongodb://db24x7_monitor:password@hostname:27017/admin?ssl=true&authSource=admin
Connection Parameters
| authSource | Database containing user credentials (usually admin) |
| replicaSet | Name of the replica set |
| ssl | Enable SSL/TLS encryption (true/false) |
| retryWrites | Enable retryable writes (recommended) |
Common authentication issues:
authSource parameter is set correctly (usually admin)Verify network connectivity:
// Test connection using mongo shell mongosh "mongodb://db24x7_monitor:password@hostname:27017/admin" // Check if MongoDB is listening netstat -an | grep 27017 // Verify firewall allows port 27017 telnet hostname 27017
Verify user roles:
use admin;
// Check user roles
db.getUser("db24x7_monitor");
// Test server status access
db.serverStatus();
// Test replica set status (if applicable)
rs.status();Common replica set problems:
replicaSet parameter matches the actual replica set nameOnce your MongoDB database is connected, you can: