mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-24 16:46:00 +01:00
8dabd67451
GitOrigin-RevId: d5a1fb056144efac5baf4b3c0b4166ac3bc7944e
86 lines
2.4 KiB
JavaScript
86 lines
2.4 KiB
JavaScript
/**
|
|
* Verify the explaining "cluster" versions of commands is not supported on any mongod
|
|
*
|
|
* @tags: [
|
|
* requires_replication,
|
|
* requires_sharding,
|
|
* ]
|
|
*/
|
|
import {ReplSetTest} from "jstests/libs/replsettest.js";
|
|
import {ShardingTest} from "jstests/libs/shardingtest.js";
|
|
|
|
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();
|
|
} |