Last active
July 24, 2025 19:51
-
-
Save dbmurphy/5d51395f8dd8fb919ad0fd426625a84b to your computer and use it in GitHub Desktop.
Get Index Build Status Mongo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Check for index build operations in currentOp with calculated progress | |
| var currentOps = db.adminCommand({ currentOp: 1 }); | |
| var indexBuilds = currentOps.inprog.filter(function(op) { | |
| return op.desc && ( | |
| op.desc.includes("createIndex") || | |
| op.desc.includes("index build") || | |
| op.desc.includes("IndexBuild") | |
| ); | |
| }); | |
| if (indexBuilds.length > 0) { | |
| print("Found " + indexBuilds.length + " index build operations:"); | |
| indexBuilds.forEach(function(op) { | |
| print(" Description: " + op.desc); | |
| print(" Duration: " + (op.secs_running || 0) + "s"); | |
| if (op.progress && op.progress.done && op.progress.total) { | |
| var percent = ((op.progress.done / op.progress.total) * 100).toFixed(1); | |
| print(" Progress: " + percent + "% (" + op.progress.done + "/" + op.progress.total + ")"); | |
| } else { | |
| print(" Progress: N/A"); | |
| } | |
| print(" Namespace: " + (op.ns || "N/A")); | |
| }); | |
| } else { | |
| print("No index build operations found"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment