summaryrefslogtreecommitdiff
path: root/jstests/sharding/change_stream_no_shards.js
blob: 0d8afc428229f90ee4499cbd72204fa8023672a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * Test that running a $changeStream aggregation on a cluster with no shards returns an empty result
 * set with a cursorID of zero.
 *
 * Requires no shards so there can't be a config shard.
 * @tags: [config_shard_incompatible]
 */
(function() {
const st = new ShardingTest({shards: 0});

const adminDB = st.s.getDB("admin");
const testDB = st.s.getDB("test");

// Test that attempting to open a stream on a single collection results in an empty, closed
// cursor response.
let csCmdRes = assert.commandWorked(
    testDB.runCommand({aggregate: "testing", pipeline: [{$changeStream: {}}], cursor: {}}));
assert.docEq([], csCmdRes.cursor.firstBatch);
assert.eq(csCmdRes.cursor.id, 0);

// Test that attempting to open a whole-db stream results in an empty, closed cursor response.
csCmdRes = assert.commandWorked(
    testDB.runCommand({aggregate: 1, pipeline: [{$changeStream: {}}], cursor: {}}));
assert.docEq([], csCmdRes.cursor.firstBatch);
assert.eq(csCmdRes.cursor.id, 0);

// Test that attempting to open a cluster-wide stream results in an empty, closed cursor
// response.
csCmdRes = assert.commandWorked(adminDB.runCommand(
    {aggregate: 1, pipeline: [{$changeStream: {allChangesForCluster: true}}], cursor: {}}));
assert.docEq([], csCmdRes.cursor.firstBatch);
assert.eq(csCmdRes.cursor.id, 0);

// Test that a regular, non-$changeStream aggregation also results in an empty cursor when no
// shards are present.
const nonCsCmdRes = assert.commandWorked(
    testDB.runCommand({aggregate: "testing", pipeline: [{$match: {}}], cursor: {}}));
assert.docEq([], nonCsCmdRes.cursor.firstBatch);
assert.eq(nonCsCmdRes.cursor.id, 0);

st.stop();
})();