summaryrefslogtreecommitdiff
path: root/jstests/sharding/change_stream_no_shards.js
blob: b6c7c7c9f610e74f52a359c50c88be634fd4e07c (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
/**
 * Test that running a $changeStream aggregation on a cluster with no shards returns an empty result
 * set with a cursorID of zero.
 */
(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();
})();