summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorDrew Paroski <drew.paroski@mongodb.com>2020-05-11 12:30:47 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-05 19:17:17 +0000
commit8147d05d7038c6bf08a0b523fd69a44c13553cf1 (patch)
tree05decf84debfeebee9046f68c8cab4fd34cfacc6 /src/mongo/shell
parent97f5866b751246f4b035ebe1cff7ac371e2430fa (diff)
downloadmongo-8147d05d7038c6bf08a0b523fd69a44c13553cf1.tar.gz
SERVER-46686 Explain does not respect maxTimeMS
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/explain_query.js5
-rw-r--r--src/mongo/shell/explainable.js19
2 files changed, 21 insertions, 3 deletions
diff --git a/src/mongo/shell/explain_query.js b/src/mongo/shell/explain_query.js
index 89a922e225a..457862f657d 100644
--- a/src/mongo/shell/explain_query.js
+++ b/src/mongo/shell/explain_query.js
@@ -150,6 +150,11 @@ var DBExplainQuery = (function() {
var explainCmd = {explain: innerCmd};
explainCmd["verbosity"] = this._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;
+ }
var explainDb = this._query._db;
diff --git a/src/mongo/shell/explainable.js b/src/mongo/shell/explainable.js
index 0761bed0333..ce356ca630e 100644
--- a/src/mongo/shell/explainable.js
+++ b/src/mongo/shell/explainable.js
@@ -28,6 +28,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.
@@ -109,7 +119,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);
}
@@ -132,7 +142,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);
};
@@ -147,8 +157,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);
};