mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
/**
|
|
* 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, config: 1});
|
|
|
|
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();
|
|
})(); |