Skip to main content

Overview

OpenSRE uses MongoDB diagnostics to investigate database-related alerts — checking server health, finding slow queries, monitoring replica sets, and analyzing collection statistics.

Prerequisites

  • MongoDB 4.0+ (4.4+ recommended)
  • Network access from the OpenSRE environment to your MongoDB instance
  • Valid credentials (if authentication is enabled)
For Atlas Admin API metrics (not a connection string), see MongoDB Atlas.

Setup

Option 1: Interactive CLI

Provide your connection string and target database when prompted.

Option 2: Environment variables

Option 3: Persistent store

Credentials

Connection string formats

URL-encode special characters in credentials: @%40, :%3A, #%23
TLS is enabled by default. For custom certificates:

Investigation tools

Enable profiling with db.setProfilingLevel(1) (slow queries only) or db.setProfilingLevel(2) (all queries).

Verify

Expected output:

Local Docker verification

Start a disposable single-node replica set without external credentials:
Seed a collection, enable profiling, complete one slow query for profiler data, and leave another running for current-operation data:
From a source checkout, run uv run opensre integrations setup mongodb and use these answers: Verify the connection:
The verifier should report MongoDB 7 and the opensre_verify database. While the slow query is still running, exercise get_mongodb_current_ops through an agent turn:
The result should include the running COLLSCAN on opensre_verify.slow. The other MongoDB tools can now read the seeded collection, profiler entries, single healthy primary member, and server status. Stop the disposable instance when finished:
This instance has no authentication or TLS. It binds only to loopback and is for local verification only.

Troubleshooting

Security

  • Use a read-only MongoDB user for monitoring — avoid admin credentials.
  • Always enable TLS in production.
  • Store connection strings in .env, never in code.
  • Rotate credentials periodically.