Administer MongoDB
MongoDB serves as the primary data store for Itential Platform. Platform stores jobs, tasks, workflow definitions, adapter configurations, and operational data in a MongoDB replica set. This guide covers the routine maintenance tasks required to keep the replica set healthy, performant, and secure.
For backup and retention policy guidance, see Archive and purge data. For detailed metrics and alert thresholds, see MongoDB metrics reference.
Before you begin
The commands in this guide assume the following environment variables are set:
Retrieve MONGO_ADMIN_PASS from your secrets manager at the start of each maintenance session and hold it only in a shell variable for the session’s duration.
The example below uses HashiCorp Vault syntax. Adjust the retrieval command to match your secrets manager’s API:
If TLS is enabled, append TLS flags to every mongosh command:
Passwords must never be stored in scripts, configuration files, or shell history. Retrieve credentials from your secrets manager at runtime and let them leave scope when the session ends.
For information about setting environment variables and Platform properties, see Platform properties and environment variables reference.
Check health and replica set status
MongoDB continuously synchronizes data across replica set members. If a node falls behind, loses connectivity, or enters a degraded state, Platform can experience job failures, write errors, or data inconsistency.
Check replica set member health
rs.status() is the single most important MongoDB health command. Run it in the mongosh shell connected to any replica set member:
Flag any member with health: 0 or stateStr: RECOVERING or UNKNOWN. For a concise view:
Identify the current primary
All writes go to the primary. Know which node it is before running any write-intensive maintenance, credential rotation, or compaction; routing writes to a secondary fails.
From a Bash prompt, useful in scripts:
Always resolve the primary at runtime; never hardcode a hostname.
Check replication lag
A lag under 10 seconds is generally acceptable. Persistent lag above 60 seconds warrants investigation. Initiating an election while a secondary is far behind can leave it unable to vote or let it become primary with stale data, so check this before any planned maintenance.
Check WiredTiger cache utilization
WiredTiger’s in-memory cache serves reads without hitting disk. operations_timed_out above zero indicates the cache is starving and queries are waiting for eviction, a leading indicator of performance degradation before it’s visible to Platform users.
Flag operations_timed_out greater than 0 and cache_full_pct above 95%.
Check system resource health
CPU saturation delays queries, disk I/O pressure slows writes and cache eviction, and swap usage causes severe latency spikes because MongoDB must wait for pages to load from disk.
MongoDB must never use swap. If swap is non-zero, investigate memory pressure before the next maintenance window.
Review replica set configuration
A misconfigured member (wrong priority, an unexpected hidden flag, missing votes) can silently prevent failover from working correctly. Review the configuration periodically and always before a planned maintenance window.
View the configuration
For election-relevant fields:
Review the index inventory
The jobs, job_data, and tasks collections in the itential database are the highest-traffic collections in a typical deployment. Without the right indexes, Platform queries fall back to full collection scans that slow down as data grows.
Index existence doesn’t confirm usefulness; if a query runs a COLLSCAN despite an index being present, use explain("executionStats") (see Diagnose performance issues).
Check database sizes and connection counts
Perform a manual failover
Without a controlled failover, stopping the primary causes the remaining members to detect the outage and hold an unplanned election, which can take 10 to 30 seconds and interrupt active Platform jobs. A manual failover moves the primary role to a specific node on your schedule, before any disruption occurs. This procedure is safe and non-destructive; no data is lost, and clients using a replica set connection string rediscover the new primary automatically.
Pre-failover checklist
Before stepping down the primary, confirm:
- All members are healthy (
health: 1,stateStr: SECONDARYorPRIMARY). - Replication lag is under 10 seconds on all secondaries.
- At least two members are eligible to become primary (
priority > 0,votes > 0).
Stepping down while a secondary is far behind can leave the replica set with no primary.
Bias the election toward a specific secondary (optional)
With no priority differences, the member that wins an election is the one with the most current oplog, which may not be the node you intend. Raise a specific member’s priority to bias the outcome:
The default priority is 1. Revert this after the failover completes.
Step down the primary
rs.stepDown() notifies the replica set gracefully, closes client connections cleanly, and gives secondaries time to catch up before the election begins:
The argument is the number of seconds the stepped-down node refuses to become primary again, giving the election time to complete. Expect MongoServerError: not primary; this is normal, and mongosh reconnects automatically.
Confirm the new primary
Wait 10 to 15 seconds, then confirm a different member shows stateStr: "PRIMARY", the former primary shows "SECONDARY", and no member is stuck in RECOVERING or UNKNOWN:
Restore priority (if you raised it)
Leaving priority elevated means that member always wins future elections, which can surprise the next person running a failover.
Manage the MongoDB service
The mongod process is managed by the systemd service of the same name. Always act on secondaries before the primary; restarting the primary triggers an election.
Check status on all nodes
A member that isn’t running is invisible to rs.status() heartbeats until it reconnects, so an OS-level check catches cases the replica set hasn’t yet registered.
Start, stop, or restart on a single node
Restarting a secondary is low-risk. Restarting the primary triggers an election and temporarily interrupts write availability. Restarting multiple nodes simultaneously can leave the replica set without enough voting members to elect a primary.
After a start or restart, verify the node rejoins:
Expect stateStr: "SECONDARY" (or "PRIMARY" if the node won an election). Don’t touch the next node until this one is healthy.
Review the configuration file
The configuration file at /etc/mongod.conf records where data is stored, cache allocation, TLS settings, and the replica set name.
Enable mongod to start on boot
Diagnose performance issues
As job and task collections grow, queries that were fast at low volume become slow, and slow queries compound under load. None of the diagnostics below modify data; they’re safe to run on a live system.
Check active operations
A stuck aggregation on jobs or tasks holds locks that block new job writes, causing Platform to queue requests and eventually time out.
To filter specifically for aggregations on the jobs or tasks collections:
Not every COLLSCAN is a problem: tailable/awaitData/$changeStream/oplog readers scan the oplog by design. A COLLSCAN on an aggregate: "jobs" or "tasks" command with secs_running > 1 seen repeatedly is the pattern to investigate.
Review slow query history (profiler)
The profiler records queries that took longest to complete, useful for intermittent slowdowns no longer visible in currentOp.
The profiler data is stored in the system.profile capped collection within each database; it isn’t persisted to disk separately from the MongoDB data files.
Explain a query
explain("executionStats") shows how MongoDB actually executed a query and how much work it did:
Don’t add an index if a similar leading key already exists in the index inventory.
Check write contention and locks
Rising write conflicts mean multiple workers are updating the same document concurrently, often job status or task queue updates competing on a small set of shared documents. This is an application-level pattern that hardware can’t fix; correlate with currentOp to identify the namespace.
Configure Transparent Huge Pages (THP)
MongoDB 8.0 introduced a new version of TCMalloc that reversed long-standing THP guidance: THP must be disabled on MongoDB 7 and below, and enabled on MongoDB 8 and above. A misconfigured setting is hard to diagnose because its effects (latency spikes, fragmentation, increased I/O) resemble many other issues.
Confirm with your team before changing THP settings on a production node.
MongoDB 8 also recommends setting the following on each node:
These changes aren’t persistent across reboots; configure them in a systemd unit or /etc/rc.local. If you’re upgrading from MongoDB 7 to 8, change THP configuration to the MongoDB 8 targets as part of the upgrade; running MongoDB 8 with THP disabled negates the TCMalloc improvements introduced in that version.
Reclaim storage space
MongoDB doesn’t automatically reclaim disk space after documents are deleted. When large numbers of jobs or tasks are archived or purged, the freed space remains allocated as fragmented free space inside the data files, which can grow storage usage even as document counts fall.
Compact a collection
compact blocks all reads and writes on the collection for its duration. Run it on a secondary during a maintenance window, or on the primary only when there are no active workflows.
Verify the reduction afterward:
Compact after a large delete (for example, archiving completed jobs), or when storageSize is significantly larger than size in collection.stats(). Don’t compact during active job processing or business hours in production.
Manage users and credentials
This deployment uses two accounts:
Your secrets manager is the authoritative source for both passwords. Update your secrets manager first, then update MongoDB to match. Updating MongoDB first creates a window where the two are out of sync.
Rotate the admin password
High-risk. The admin account has full control over the instance, including creating users, dropping databases, and modifying the replica set configuration.
Update the secret in your secrets manager
Generate a new password and store it under the key mongoDbAdmin before making any change to MongoDB.
Rotate the itential service account password
The itential account is the credential Platform uses for every database read and write. Because Platform reads it from your secrets manager at startup, rotating it requires a Platform restart to pick up the change.
Retrieve the new password
The example below uses HashiCorp Vault syntax; adjust the retrieval command to match your secrets manager’s API:
Restart Platform
Restart Platform on each node so it reconnects with the new credential from your secrets manager. See Manage the Platform service.
Inspect logs
MongoDB logs are written in structured JSON, with a severity field ("s") where "I" is informational, "W" is warning, and "E" is error. The log file is at /var/log/mongodb/mongod.log by default; confirm against systemLog.path in /etc/mongod.conf.
Search for errors and warnings
Search for a specific pattern
View recent log entries on a single node
For a human-readable format, pipe through jq to extract key fields:
Rotate TLS certificates
An expired certificate breaks replication, interrupts Platform’s database access, and can cause a primary election to fail if secondaries can’t reach the primary. TLS certificate files are referenced in /etc/mongod.conf under net.tls:
Verify the new certificate before deploying
Don’t proceed if openssl verify errors or the modulus hashes don’t match.
Copy new certificate files to each node
Back up the previous files first (mongod.pem.bak, ca.pem.bak) so rollback is a one-file restore.
Roll out the restart: secondaries first, primary last
Confirm it rejoined as SECONDARY before touching the next node:
For the primary, step down first (see Perform a manual failover), then restart what is now a secondary: