summaryrefslogtreecommitdiff
path: root/jstests/hooks
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2019-01-07 10:27:46 -0500
committerRandolph Tan <randolph@10gen.com>2019-01-07 11:08:05 -0500
commit3d28a55677f555092d94b2a2908a8a37cdf07db9 (patch)
treef8b8ec9c481c444960d7ff2144a3edc2fb518fc6 /jstests/hooks
parente139a33d9f872f8e850f85a39294814803e6ccc3 (diff)
downloadmongo-3d28a55677f555092d94b2a2908a8a37cdf07db9.tar.gz
SERVER-37853 Create sharded_core_txn with balancer suite
This reverts commit 907c8c786e26414735892bfbe763cd67e7f7e7e4.
Diffstat (limited to 'jstests/hooks')
-rw-r--r--jstests/hooks/drop_sharded_collections.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/jstests/hooks/drop_sharded_collections.js b/jstests/hooks/drop_sharded_collections.js
new file mode 100644
index 00000000000..5758e3027e5
--- /dev/null
+++ b/jstests/hooks/drop_sharded_collections.js
@@ -0,0 +1,33 @@
+/**
+ * Drops all sharded collections (except for collections used internally,
+ * like config.system.sessions).
+ */
+(function() {
+ "use strict";
+
+ load("jstests/libs/fixture_helpers.js"); // For isMongos.
+
+ assert.neq(typeof db, 'undefined', 'No `db` object, is the shell connected to a mongod?');
+ assert(FixtureHelpers.isMongos(db), "not connected to mongos");
+
+ let balSettingResult = assert.commandWorked(db.adminCommand({balancerStatus: 1}));
+ if (balSettingResult.mode !== 'off') {
+ assert.commandWorked(db.adminCommand({balancerStop: 1}));
+ }
+
+ db.getSiblingDB('config').collections.find().forEach(collEntry => {
+ if (collEntry._id !== 'config.system.sessions') {
+ let nsSplit = collEntry._id.split('.');
+ const dbName = nsSplit.shift();
+ const collName = nsSplit.join('.');
+
+ // Note: drop also cleans up tags and chunks associated with ns.
+ assert.commandWorked(db.getSiblingDB(dbName).runCommand({drop: collName}));
+ }
+ });
+
+ // Turn balancer back on if it was not off earlier.
+ if (balSettingResult.mode !== 'off') {
+ assert.commandWorked(db.adminCommand({balancerStart: 1}));
+ }
+})();