summaryrefslogtreecommitdiff
path: root/jstests/sharding/agg_write_stages_cannot_run_on_mongos.js
blob: 740eade7b12e4e13fea5549d48263148dfad3946 (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
43
44
45
46
// Tests that special stages which must run on mongos cannot be run in combination with an $out or
// $merge stage.
(function() {
    "use strict";

    const st = new ShardingTest({shards: 2, rs: {nodes: 1}, config: 1});
    const db = st.s0.getDB("db");
    const admin = st.s0.getDB("admin");

    // Create a collection in the db to get around optimizations that will do nothing in lieu of
    // failing when the db is empty.
    assert.commandWorked(db.runCommand({create: "coll"}));

    // These should fail because the initial stages require mongos execution and $out/$merge
    // requires shard execution.
    assert.commandFailedWithCode(
        db.runCommand(
            {aggregate: 1, pipeline: [{$listLocalSessions: {}}, {$out: "test"}], cursor: {}}),
        ErrorCodes.IllegalOperation);
    assert.commandFailedWithCode(
        admin.runCommand(
            {aggregate: 1, pipeline: [{$currentOp: {localOps: true}}, {$out: "test"}], cursor: {}}),
        ErrorCodes.IllegalOperation);
    assert.commandFailedWithCode(
        db.runCommand({aggregate: 1, pipeline: [{$changeStream: {}}, {$out: "test"}], cursor: {}}),
        ErrorCodes.IllegalOperation);

    assert.commandFailedWithCode(db.runCommand({
        aggregate: 1,
        pipeline: [{$listLocalSessions: {}}, {$merge: {into: "test"}}],
        cursor: {}
    }),
                                 ErrorCodes.IllegalOperation);
    assert.commandFailedWithCode(admin.runCommand({
        aggregate: 1,
        pipeline: [{$currentOp: {localOps: true}}, {$merge: {into: "test"}}],
        cursor: {}
    }),
                                 ErrorCodes.IllegalOperation);
    assert.commandFailedWithCode(
        db.runCommand(
            {aggregate: 1, pipeline: [{$changeStream: {}}, {$merge: {into: "test"}}], cursor: {}}),
        ErrorCodes.IllegalOperation);

    st.stop();
}());