summaryrefslogtreecommitdiff
path: root/jstests/sharding/cluster_create_indexes_always_routes_through_primary.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/sharding/cluster_create_indexes_always_routes_through_primary.js')
-rw-r--r--jstests/sharding/cluster_create_indexes_always_routes_through_primary.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/jstests/sharding/cluster_create_indexes_always_routes_through_primary.js b/jstests/sharding/cluster_create_indexes_always_routes_through_primary.js
new file mode 100644
index 00000000000..6c661e0abac
--- /dev/null
+++ b/jstests/sharding/cluster_create_indexes_always_routes_through_primary.js
@@ -0,0 +1,20 @@
+// Ensure that a call to createIndexes in a sharded cluster will route to the primary, even when
+// setSlaveOk() is set to true.
+(function() {
+'use strict';
+
+let st = new ShardingTest({shards: {rs0: {nodes: 2}}});
+const testDBName = jsTestName();
+const collName = 'coll';
+const testDB = st.s.getDB(testDBName);
+
+assert.commandWorked(testDB.adminCommand({enableSharding: testDBName}));
+assert.commandWorked(
+ testDB.adminCommand({shardCollection: testDB[collName].getFullName(), key: {x: 1}}));
+
+st.s.setSlaveOk(true);
+assert.commandWorked(
+ testDB.runCommand({createIndexes: collName, indexes: [{key: {a: 1}, name: "index"}]}));
+
+st.stop();
+})();