diff options
author | Kevin Albertson <kevin.albertson@10gen.com> | 2018-01-04 16:27:22 -0500 |
---|---|---|
committer | Kevin Albertson <kevin.albertson@10gen.com> | 2018-01-31 10:25:43 -0500 |
commit | 28c18ba63785d6cbf0ae27c4d5031255b6b79b2c (patch) | |
tree | 135138f6f84a876f55b1c639e8983222d85e0a99 /src/mongo/shell | |
parent | e8596ec81cd0448310e40d9c2af8f8161dae3965 (diff) | |
download | mongo-28c18ba63785d6cbf0ae27c4d5031255b6b79b2c.tar.gz |
SERVER-32065 support retryWrites URI param in shell
Diffstat (limited to 'src/mongo/shell')
-rw-r--r-- | src/mongo/shell/dbshell.cpp | 9 | ||||
-rw-r--r-- | src/mongo/shell/mongo.js | 6 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp index 4dfb85d835a..83e07975a68 100644 --- a/src/mongo/shell/dbshell.cpp +++ b/src/mongo/shell/dbshell.cpp @@ -784,10 +784,11 @@ int _main(int argc, char* argv[], char** envp) { << getURIFromArgs(processedURI, shellGlobalParams.dbhost, shellGlobalParams.port) << "\");"; - if (shellGlobalParams.shouldRetryWrites) { - // If the user specified --retryWrites to the mongo shell, then we replace the global - // `db` object with a DB object that has retryable writes enabled. - ss << "db = db.getMongo().startSession({retryWrites: true}).getDatabase(db.getName());"; + if (shellGlobalParams.shouldRetryWrites || parsedURI.getRetryWrites()) { + // If the --retryWrites cmdline argument or retryWrites URI param was specified, then + // replace the global `db` object with a DB object started in a session. The resulting + // Mongo connection checks its _retryWrites property. + ss << "db = db.getMongo().startSession().getDatabase(db.getName());"; } mongo::shell_utils::_dbConnect = ss.str(); diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js index 2a477659eb8..e789e284795 100644 --- a/src/mongo/shell/mongo.js +++ b/src/mongo/shell/mongo.js @@ -417,7 +417,11 @@ Mongo.prototype.getClusterTime = function() { return this._clusterTime; }; -Mongo.prototype.startSession = function startSession(options) { +Mongo.prototype.startSession = function startSession(options = {}) { + // Set retryWrites if not already set on options. + if (!options.hasOwnProperty("retryWrites") && this.hasOwnProperty("_retryWrites")) { + options.retryWrites = this._retryWrites; + } return new DriverSession(this, options); }; |