summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/cluster_explain_commands_not_supported.js
blob: 3aa315382e30cbfcc412cc3cb6f02cc73ec01dbf (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
 * Verify the explaining "cluster" versions of commands is not supported on any mongod
 *
 * @tags: [
 *   requires_replication,
 *   requires_sharding,
 * ]
 */
(function() {
"use strict";

const kDbName = "cluster_explain_commands";
const kCollName = "bar";

const clusterCommandsCases = [
    {cmd: {explain: {clusterAggregate: kCollName, pipeline: [{$match: {}}], cursor: {}}}},
    {cmd: {explain: {clusterCount: "x"}}},
    {cmd: {explain: {clusterFind: kCollName}}},
    {cmd: {explain: {clusterInsert: kCollName, documents: [{x: 1}]}}},
    {cmd: {explain: {clusterUpdate: kCollName, updates: [{q: {doesNotExist: 1}, u: {x: 1}}]}}},
    {cmd: {explain: {clusterDelete: `${kCollName}`, deletes: [{q: {}, limit: 1}]}}}
];

function runTestCaseExpectFail(conn, testCase, code) {
    assert.commandFailedWithCode(
        conn.getDB(kDbName).runCommand(testCase.cmd), code, tojson(testCase.cmd));
}

//
// Cluster explain commands not supported on standalone mongods
//
{
    const standalone = MongoRunner.runMongod({});
    assert(standalone);

    for (let testCase of clusterCommandsCases) {
        runTestCaseExpectFail(standalone, testCase, ErrorCodes.CommandNotSupported);
    }

    MongoRunner.stopMongod(standalone);
}

//
// Cluster explain commands not supported on replica set mongods
//
{
    const rst = new ReplSetTest({nodes: 1});
    rst.startSet();
    rst.initiate();

    for (let testCase of clusterCommandsCases) {
        runTestCaseExpectFail(rst.getPrimary(), testCase, ErrorCodes.CommandNotSupported);
    }

    rst.stopSet();
}

{
    const st = new ShardingTest({mongos: 1, shards: 1, config: 1});

    //
    // Cluster explain commands do not exist on mongos.
    //

    for (let testCase of clusterCommandsCases) {
        runTestCaseExpectFail(st.s, testCase, ErrorCodes.CommandNotFound);
    }

    //
    // Cluster explain commands are not supported on a config server node.
    //

    for (let testCase of clusterCommandsCases) {
        runTestCaseExpectFail(st.configRS.getPrimary(), testCase, ErrorCodes.CommandNotSupported);
    }

    //
    // Cluster explain commands are not supported sharding enabled shardsvr.
    //

    for (let testCase of clusterCommandsCases) {
        runTestCaseExpectFail(st.rs0.getPrimary(), testCase, ErrorCodes.CommandNotSupported);
    }

    st.stop();
}
}());