dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/mongodb/#89
Script #89
mongodb
Lockingread-onlyMin Version: 4.0

MongoDB Operations Waiting for Locks

Lists operations with waitingForLock set and the resource they wait on. Diagnoses slowdowns from write conflicts and lock pressure.

#locks#waitingForLock#currentOp
mongodb · javascript
db.getSiblingDB("admin").aggregate([
  { $currentOp: { allUsers: true } },
  { $match: { waitingForLock: true } },
  { $project: { opid: 1, op: 1, ns: 1, secs_running: 1, lockStats: 1, command: 1, client: 1 } },
  { $sort: { secs_running: -1 } }
]);
Operational Notes & Remediation Guidance

Verify in a staging environment prior to running in production. This is a read-only diagnostic query; it does not acquire exclusive locks.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 4.0).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.