summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/cluster_explain_commands_require_cluster_node.js
blob: 5e009345d806de756af2e75c49b6553caf7df107 (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
/**
 * Verify the explaining "cluster" versions of commands is rejected on a non shardsvr mongod.
 *
 * @tags: [
 *   requires_replication,
 * ]
 */
(function() {
"use strict";

const kDbName = "cluster_explain_commands";
const kCollName = "bar";
const rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();

const clusterCommandsCases = [
    {cmd: {explain: {clusterAggregate: kCollName, pipeline: [{$match: {}}], cursor: {}}}},
    {cmd: {explain: {clusterCount: "x"}}},
    {cmd: {explain: {clusterDelete: kCollName, deletes: [{q: {}, limit: 1}]}}},
    {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));
}

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

rst.stopSet();
}());