summaryrefslogtreecommitdiff
path: root/src/mongo/shell/utils.js
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2018-06-22 16:54:24 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2018-07-10 18:25:08 -0400
commitbb9f225e47faacb95ae9e5658313a5ebf56f37bf (patch)
tree5931d479655484bc909b959357cfee2a91eebd26 /src/mongo/shell/utils.js
parent55bf25f29caab71487178302e471120e1f2b0a6a (diff)
downloadmongo-bb9f225e47faacb95ae9e5658313a5ebf56f37bf.tar.gz
SERVER-35758 Mongo shell prompt errors when running transactions after overriding 'db'
Diffstat (limited to 'src/mongo/shell/utils.js')
-rw-r--r--src/mongo/shell/utils.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
index dafdac4101d..ec437903154 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -1056,6 +1056,29 @@ shellHelper.show = function(what) {
};
+__promptWrapper__ = function(promptFunction) {
+ // Call promptFunction directly if the global "db" is not defined, e.g. --nodb.
+ if (typeof db === 'undefined' || !(db instanceof DB)) {
+ __prompt__ = promptFunction();
+ return;
+ }
+
+ // Stash the global "db" for the prompt function to make sure the session
+ // of the global "db" isn't accessed by the prompt function.
+ let originalDB = db;
+ try {
+ db = originalDB.getMongo().getDB(originalDB.getName());
+ // Setting db._session to be a _DummyDriverSession instance makes it so that
+ // a logical session id isn't included in the isMaster and replSetGetStatus
+ // commands and therefore won't interfere with the session associated with the
+ // global "db" object.
+ db._session = new _DummyDriverSession(db.getMongo());
+ __prompt__ = promptFunction();
+ } finally {
+ db = originalDB;
+ }
+};
+
Math.sigFig = function(x, N) {
if (!N) {
N = 3;