Skip to content

Instantly share code, notes, and snippets.

@dbmurphy
Last active July 24, 2025 19:51
Show Gist options
  • Select an option

  • Save dbmurphy/5d51395f8dd8fb919ad0fd426625a84b to your computer and use it in GitHub Desktop.

Select an option

Save dbmurphy/5d51395f8dd8fb919ad0fd426625a84b to your computer and use it in GitHub Desktop.
Get Index Build Status Mongo
// 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