summaryrefslogtreecommitdiff
path: root/src/mongo/shell/explainable.js
diff options
context:
space:
mode:
authorDrew Paroski <drew.paroski@mongodb.com>2020-05-05 12:09:09 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-09 08:16:44 +0000
commitd7d3a0d782ced557c26b9eb81ea97cc242762c8f (patch)
tree36488923a7fd7ca164992eb2de4212c33405a1c1 /src/mongo/shell/explainable.js
parent2546fe1c22b0777ca68e604376900ea11f10ee3a (diff)
downloadmongo-d7d3a0d782ced557c26b9eb81ea97cc242762c8f.tar.gz
SERVER-46686 Update explain() shell command to propagate "maxTimeMS" arg to top-level
Diffstat (limited to 'src/mongo/shell/explainable.js')
-rw-r--r--src/mongo/shell/explainable.js21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/mongo/shell/explainable.js b/src/mongo/shell/explainable.js
index 08a900c5274..c47c7fab7cd 100644
--- a/src/mongo/shell/explainable.js
+++ b/src/mongo/shell/explainable.js
@@ -35,6 +35,16 @@ var Explainable = (function() {
return explainResult;
};
+ var buildExplainCmd = function(innerCmd, verbosity) {
+ var explainCmd = {"explain": innerCmd, "verbosity": verbosity};
+ // If "maxTimeMS" is set on innerCmd, it needs to be propagated to the top-level
+ // of explainCmd so that it has the intended effect.
+ if (innerCmd.hasOwnProperty("maxTimeMS")) {
+ explainCmd.maxTimeMS = innerCmd.maxTimeMS;
+ }
+ return explainCmd;
+ };
+
function constructor(collection, verbosity) {
//
// Private vars.
@@ -117,7 +127,7 @@ var Explainable = (function() {
let aggCmd = Object.extend(
{"aggregate": this._collection.getName(), "pipeline": pipeline}, extraOptsCopy);
- let explainCmd = {"explain": aggCmd, "verbosity": this._verbosity};
+ let explainCmd = buildExplainCmd(aggCmd, this._verbosity);
let explainResult = this._collection.runReadCommand(explainCmd);
return throwOrReturn(explainResult);
}
@@ -140,7 +150,7 @@ var Explainable = (function() {
this.findAndModify = function(params) {
var famCmd = Object.extend({"findAndModify": this._collection.getName()}, params);
- var explainCmd = {"explain": famCmd, "verbosity": this._verbosity};
+ var explainCmd = buildExplainCmd(famCmd, this._verbosity);
var explainResult = this._collection.runReadCommand(explainCmd);
return throwOrReturn(explainResult);
};
@@ -155,8 +165,11 @@ var Explainable = (function() {
if (options && options.hasOwnProperty("collation")) {
distinctCmd.collation = options.collation;
}
+ if (options && options.hasOwnProperty("maxTimeMS")) {
+ distinctCmd.maxTimeMS = options.maxTimeMS;
+ }
- var explainCmd = {explain: distinctCmd, verbosity: this._verbosity};
+ var explainCmd = buildExplainCmd(distinctCmd, this._verbosity);
var explainResult = this._collection.runReadCommand(explainCmd);
return throwOrReturn(explainResult);
};
@@ -235,7 +248,7 @@ var Explainable = (function() {
else
Object.extend(mapReduceCmd, optionsObjOrOutString);
- const explainCmd = {"explain": mapReduceCmd, "verbosity": this._verbosity};
+ const explainCmd = buildExplainCmd(mapReduceCmd, this._verbosity);
const explainResult = this._collection.runCommand(explainCmd);
return throwOrReturn(explainResult);
};