summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Judd <ben.judd@10gen.com>2018-05-31 18:00:10 -0400
committerBen Judd <ben.judd@10gen.com>2018-06-08 11:04:07 -0400
commitb949f46b0542d6fa7be6d0d7174f338e23c059cf (patch)
tree1791a59e49f1debafa59c4d50993a775cd1cc548
parentd42c9ded55e1fe7fc19b47c9bf86fb1949aa6010 (diff)
downloadmongo-b949f46b0542d6fa7be6d0d7174f338e23c059cf.tar.gz
SERVER-35172 'ns' field is no longer duplicated in response to dropCollection with WCE
(cherry picked from commit 315d216282d9182078e7ae8a994747caab812dc9)
-rw-r--r--jstests/noPassthrough/dropcollection_duplicate_fields.js29
-rw-r--r--src/mongo/db/catalog/drop_collection.cpp4
2 files changed, 32 insertions, 1 deletions
diff --git a/jstests/noPassthrough/dropcollection_duplicate_fields.js b/jstests/noPassthrough/dropcollection_duplicate_fields.js
new file mode 100644
index 00000000000..a2a1c1c8839
--- /dev/null
+++ b/jstests/noPassthrough/dropcollection_duplicate_fields.js
@@ -0,0 +1,29 @@
+/*
+ * SERVER-35172: Test that dropCollection does not return a message containing multiple "ns" fields
+ * @tags: [requires_wiredtiger]
+ */
+
+(function() {
+ "use strict";
+ var conn = MongoRunner.runMongod();
+ var db = conn.getDB('test');
+
+ let coll = db.dropcollection_duplicate_fields;
+ // Repeat 100 times for the sake of probabilities
+ for (let i = 0; i < 100; i++) {
+ coll.drop();
+ coll.insert({x: 1});
+
+ assert.commandWorked(db.adminCommand(
+ {configureFailPoint: 'WTWriteConflictException', mode: {activationProbability: 0.1}}));
+
+ // will blow up if res is not valid
+ let res = db.runCommand({drop: 'dropcollection_duplicate_fields'});
+
+ assert.commandWorked(
+ db.adminCommand({configureFailPoint: 'WTWriteConflictException', mode: "off"}));
+ }
+
+ MongoRunner.stopMongod(conn);
+
+})();
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp
index e9e816651a2..ccfc5050987 100644
--- a/src/mongo/db/catalog/drop_collection.cpp
+++ b/src/mongo/db/catalog/drop_collection.cpp
@@ -82,7 +82,9 @@ Status dropCollection(OperationContext* opCtx,
}
WriteUnitOfWork wunit(opCtx);
- result.append("ns", collectionName.ns());
+ if (!result.hasField("ns")) {
+ result.append("ns", collectionName.ns());
+ }
if (coll) {
invariant(!view);