summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Guo <robert.guo@mongodb.com>2021-01-07 09:40:48 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-19 15:36:32 +0000
commitf3b3164a196fa930b17ac2f703db433d8fc79f36 (patch)
tree5e6d39a18b010874ed7cee991d1a60d02d78ace9
parentc4576b8312fb219cc3e00202c52a4f59e1ad2ca3 (diff)
downloadmongo-f3b3164a196fa930b17ac2f703db433d8fc79f36.tar.gz
SERVER-38938 include metadata in command response
-rw-r--r--src/mongo/scripting/mozjs/internedstring.defs1
-rw-r--r--src/mongo/scripting/mozjs/mongo.cpp6
-rw-r--r--src/mongo/shell/assert.js9
3 files changed, 15 insertions, 1 deletions
diff --git a/src/mongo/scripting/mozjs/internedstring.defs b/src/mongo/scripting/mozjs/internedstring.defs
index fe3d5e6aa49..2fc2a8e5eff 100644
--- a/src/mongo/scripting/mozjs/internedstring.defs
+++ b/src/mongo/scripting/mozjs/internedstring.defs
@@ -12,6 +12,7 @@ MONGO_MOZJS_INTERNED_STRING(_bson, "_bson")
MONGO_MOZJS_INTERNED_STRING(code, "code")
MONGO_MOZJS_INTERNED_STRING(_collection, "_collection")
MONGO_MOZJS_INTERNED_STRING(columnNumber, "columnNumber")
+MONGO_MOZJS_INTERNED_STRING(_commandObj, "_commandObj")
MONGO_MOZJS_INTERNED_STRING(constructor, "constructor")
MONGO_MOZJS_INTERNED_STRING(_cursor, "_cursor")
MONGO_MOZJS_INTERNED_STRING(database, "database")
diff --git a/src/mongo/scripting/mozjs/mongo.cpp b/src/mongo/scripting/mozjs/mongo.cpp
index 8b643f3476d..0358c15ba2d 100644
--- a/src/mongo/scripting/mozjs/mongo.cpp
+++ b/src/mongo/scripting/mozjs/mongo.cpp
@@ -279,6 +279,12 @@ void MongoBase::Functions::runCommand::call(JSContext* cx, JS::CallArgs args) {
// Also, we make a copy here because we want a copy after we dump cmdRes
ValueReader(cx, args.rval()).fromBSON(cmdRes.getOwned(), nullptr, false /* read only */);
setHiddenMongo(cx, std::get<1>(resTuple), conn.get(), args);
+
+ ObjectWrapper o(cx, args.rval());
+ if (!o.hasField(InternedString::_commandObj)) {
+ o.defineProperty(
+ InternedString::_commandObj, args.get(1), JSPROP_READONLY | JSPROP_PERMANENT);
+ }
}
void MongoBase::Functions::runCommandWithMetadata::call(JSContext* cx, JS::CallArgs args) {
diff --git a/src/mongo/shell/assert.js b/src/mongo/shell/assert.js
index 54f5403b53e..4cf065304ba 100644
--- a/src/mongo/shell/assert.js
+++ b/src/mongo/shell/assert.js
@@ -688,7 +688,14 @@ assert = (function() {
// Keep this as a function so we don't call tojson if not necessary.
const makeFailMsg = () => {
- return _buildAssertionMessage(msg, "command failed: " + tojson(res));
+ let prefix = "command failed: " + tojson(res);
+ if (typeof res._commandObj === "object" && res._commandObj !== null) {
+ prefix += " with original command request: " + tojson(res._commandObj);
+ }
+ if (typeof res._mongo === "object" && res._mongo !== null) {
+ prefix += " on connection: " + res._mongo;
+ }
+ return _buildAssertionMessage(msg, prefix);
};
if (_isWriteResultType(res)) {