summaryrefslogtreecommitdiff
path: root/src/mongo/shell/mongo.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/shell/mongo.js')
-rw-r--r--src/mongo/shell/mongo.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index faf2b624b66..e574f0b99d7 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -263,6 +263,10 @@ connect = function(url, user, pass) {
}
}
+ if (_shouldUseImplicitSessions()) {
+ chatty("Implicit session: " + db.getSession());
+ }
+
// Implicit sessions should not be used when opening a connection. In particular, the buildInfo
// command is erroneously marked as requiring auth in MongoDB 3.6 and therefore fails if a
// logical session id is included in the request.
@@ -445,14 +449,30 @@ Mongo.prototype._getDefaultSession = function getDefaultSession() {
// a logical session id. These implicit sessions are intentionally not causally consistent. If
// implicit sessions have been globally disabled, a dummy session is used instead of a real one.
if (!this.hasOwnProperty("_defaultSession")) {
- this._defaultSession = _shouldUseImplicitSessions()
- ? this.startSession({causalConsistency: false})
- : new _DummyDriverSession(this);
+ if (_shouldUseImplicitSessions()) {
+ try {
+ this._defaultSession = this.startSession({causalConsistency: false});
+ } catch (e) {
+ if (e instanceof DriverSession.UnsupportedError) {
+ chatty("WARNING: No implicit session: " + e.message);
+ this._setDummyDefaultSession();
+ } else {
+ print("ERROR: Implicit session failed: " + e.message);
+ throw(e);
+ }
+ }
+ } else {
+ this._setDummyDefaultSession();
+ }
this._defaultSession._isExplicit = false;
}
return this._defaultSession;
};
+Mongo.prototype._setDummyDefaultSession = function setDummyDefaultSession() {
+ this._defaultSession = new _DummyDriverSession(this);
+};
+
Mongo.prototype.isCausalConsistency = function isCausalConsistency() {
if (!this.hasOwnProperty("_causalConsistency")) {
this._causalConsistency = false;