summaryrefslogtreecommitdiff
path: root/jstests/sharding/sample_direct_connection.js
diff options
context:
space:
mode:
authorEric Cox <eric.cox@mongodb.com>2021-08-06 21:17:43 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-10 17:11:12 +0000
commitf3e8bfb0ea52ae167e097f3f3fd9bf183e6b4a8a (patch)
treed8e0c0dc3b0e82ad1fb16e93f96afda7ef661c91 /jstests/sharding/sample_direct_connection.js
parentde7bbb26cda49c907bbbed5c6384c47ae1b050dd (diff)
downloadmongo-f3e8bfb0ea52ae167e097f3f3fd9bf183e6b4a8a.tar.gz
SERVER-59071 Treat '$sample' as unsharded when connecting directly to shards
Diffstat (limited to 'jstests/sharding/sample_direct_connection.js')
-rw-r--r--jstests/sharding/sample_direct_connection.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/jstests/sharding/sample_direct_connection.js b/jstests/sharding/sample_direct_connection.js
new file mode 100644
index 00000000000..c435490c2f8
--- /dev/null
+++ b/jstests/sharding/sample_direct_connection.js
@@ -0,0 +1,23 @@
+// This test ensures that an aggregation pipeline with a $sample stage can be issued through a
+// direct connection to a shard without failing, and $sample behaves as if we sampled an unsharded
+// collection.
+(function() {
+let st = new ShardingTest({shards: 1});
+
+assert.commandWorked(st.adminCommand({enableSharding: 'test'}));
+assert.commandWorked(st.adminCommand({shardCollection: 'test.sharded', key: {x: 1}}));
+const testDB = st.s.getDB('test');
+
+// We must have >100 samples to attempt the storage optimized sample path.
+for (let x = 0; x < 101; x++) {
+ assert.commandWorked(testDB.foo.insert({x: x}));
+}
+
+const shardDB = st.rs0.getPrimary().getDB('test');
+
+const res = assert.commandWorked(
+ shardDB.runCommand({aggregate: 'foo', pipeline: [{$sample: {size: 3}}], cursor: {}}));
+assert.eq(res.cursor.firstBatch.length, 3);
+
+st.stop();
+})();