summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-11-24 19:11:39 -0500
committerDavid Storch <david.storch@10gen.com>2014-12-02 14:51:14 -0500
commit389b5b48218f5ee73e4164afb84ea5fa2ba7646e (patch)
tree7216dcdec94cf5a8c58240d91686c75a7035203c /src/mongo/shell
parente2a08e2cd6fb0ebd226c22cae6ba73425613e477 (diff)
downloadmongo-389b5b48218f5ee73e4164afb84ea5fa2ba7646e.tar.gz
SERVER-15908 SERVER-15956 fix explain shell helper handling of slaveOk and readPref
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/explain_query.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/mongo/shell/explain_query.js b/src/mongo/shell/explain_query.js
index cb7af06cddd..1c7d25ee5f1 100644
--- a/src/mongo/shell/explain_query.js
+++ b/src/mongo/shell/explain_query.js
@@ -160,7 +160,25 @@ var DBExplainQuery = (function() {
var explainCmd = {explain: innerCmd};
explainCmd["verbosity"] = this._verbosity;
- var explainResult = this._query._db.runCommand(explainCmd);
+ // We explicitly run a find against the $cmd collection instead of using the
+ // runCommand helper so that we can set a read preference on the command.
+ var cmdColl = this._query._db.getCollection("$cmd");
+ var cmdQuery = cmdColl.find(explainCmd,
+ {}, // projection
+ -1, // limit
+ 0, // skip
+ 0, // batchSize
+ this._query._options);
+
+ // Handle read preference.
+ if ("$readPreference" in this._query._query) {
+ // A read preference was set on the query. Pull the read pref up so that it is
+ // set on the explain command.
+ var prefObj = this._query._query.$readPreference;
+ cmdQuery.readPref(prefObj.mode, prefObj.tags);
+ }
+
+ var explainResult = cmdQuery.next();
if (!explainResult.ok && explainResult.code === CMD_NOT_FOUND_CODE) {
// One of the shards doesn't have the explain command available. Retry using
// the legacy $explain format, which should be supported by all shards.