diff options
author | Katherine Wu <katherine.wu@mongodb.com> | 2021-03-29 17:31:07 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-29 21:56:24 +0000 |
commit | dcad7b7b9bf075606b77c0c63ba78df617de50ef (patch) | |
tree | 8b970e981c8a84f544860572e21156de6132a2c8 /src/mongo/shell | |
parent | 434ff838950d360bed1456c9307dd9c173323ac0 (diff) | |
download | mongo-dcad7b7b9bf075606b77c0c63ba78df617de50ef.tar.gz |
Revert "SERVER-47603 Rewrite db.currentOp() shell helper in terms of $currentOp aggregation stage"
This reverts commit 30fd64abd177d11362f3b3460897eff1f8b7ce53.
Diffstat (limited to 'src/mongo/shell')
-rw-r--r-- | src/mongo/shell/db.js | 64 |
1 files changed, 15 insertions, 49 deletions
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js index d6a59f8100c..bcdcea166a0 100644 --- a/src/mongo/shell/db.js +++ b/src/mongo/shell/db.js @@ -814,24 +814,7 @@ var commandUnsupported = function(res) { }; DB.prototype.currentOp = function(arg) { - try { - const results = this.currentOpCursor(arg).toArray(); - let res = {"inprog": results.length > 0 ? results : [], "ok": 1}; - Object.defineProperty(res, "fsyncLock", { - get: function() { - throw Error( - "fsyncLock is no longer included in the currentOp shell helper, run db.runCommand({currentOp: 1}) instead."); - } - }); - return res; - } catch (e) { - return {"ok": 0, "code": e.code, "errmsg": "Error executing $currentOp: " + e.message}; - } -}; -DB.prototype.currentOP = DB.prototype.currentOp; - -DB.prototype.currentOpCursor = function(arg) { - let q = {}; + var q = {}; if (arg) { if (typeof (arg) == "object") Object.extend(q, arg); @@ -839,40 +822,23 @@ DB.prototype.currentOpCursor = function(arg) { q["$all"] = true; } - // Convert the incoming currentOp command into an equivalent aggregate command - // of the form {aggregate:1, pipeline: [{$currentOp: {idleConnections: $all, allUsers: - // !$ownOps, truncateOps: false}}, {$match: {<user-defined filter>}}], cursor:{}}. - let pipeline = []; - - let currOpArgs = {}; - let currOpStage = {"$currentOp": currOpArgs}; - currOpArgs["allUsers"] = !q["$ownOps"]; - currOpArgs["idleConnections"] = !!q["$all"]; - currOpArgs["truncateOps"] = false; - - pipeline.push(currOpStage); - - let matchArgs = {}; - let matchStage = {"$match": matchArgs}; - for (const fieldname of Object.keys(q)) { - if (fieldname !== "$all" && fieldname !== "$ownOps" && fieldname !== "$truncateOps") { - matchArgs[fieldname] = q[fieldname]; + var commandObj = {"currentOp": 1}; + Object.extend(commandObj, q); + var res = this.adminCommand(commandObj); + if (commandUnsupported(res)) { + // always send legacy currentOp with default (null) read preference (SERVER-17951) + const session = this.getSession(); + const readPreference = session.getOptions().getReadPreference(); + try { + session.getOptions().setReadPreference(null); + res = this.getSiblingDB("admin").$cmd.sys.inprog.findOne(q); + } finally { + session.getOptions().setReadPreference(readPreference); } } - - pipeline.push(matchStage); - - // The legacy db.currentOp() shell helper ignored read preference. To preserve this behavior we - // will temporarily set the session's read preference to null. - const session = this.getSession(); - const readPreference = session.getOptions().getReadPreference(); - try { - session.getOptions().setReadPreference("primaryPreferred"); - return this.getSiblingDB("admin").aggregate(pipeline); - } finally { - session.getOptions().setReadPreference(readPreference); - } + return res; }; +DB.prototype.currentOP = DB.prototype.currentOp; DB.prototype.killOp = function(op) { if (!op) |