summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/commands/pipeline_command.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp
index 395eb75f74e..3926026404f 100644
--- a/src/mongo/db/commands/pipeline_command.cpp
+++ b/src/mongo/db/commands/pipeline_command.cpp
@@ -341,15 +341,22 @@ namespace {
}
try {
+ // Unless set to true, the ClientCursor created above will be deleted on block exit.
+ bool keepCursor = false;
+
+ // If both explain and cursor are specified, explain wins.
if (pPipeline->isExplain()) {
result << "stages" << Value(pPipeline->writeExplainOps());
}
else if (isCursorCommand(cmdObj)) {
handleCursorCommand(ns, pin.get(), runner, cmdObj, result);
+ keepCursor = true;
}
else {
pPipeline->run(result);
}
+
+ if (!keepCursor && pin) pin->deleteUnderlying();
}
catch (...) {
// Clean up cursor on way out of scope.