Files
mongo/jstests/sharding/query/aggregation_internal_parameters.js
Kishore Devireddy d4fca5696e SERVER-84801: Remove replication.eMRC from options (#22851)
GitOrigin-RevId: e8ddf575dbc4d44ccd92f341c2d1ffe7ad53ad7b
2024-06-03 22:46:18 +00:00

130 lines
4.5 KiB
JavaScript

/**
* Tests that mongoS rejects 'aggregate' commands which explicitly set any of the
* parameters that mongoS uses internally when communicating with the shards.
*/
import {
WriteWithoutShardKeyTestUtil
} from "jstests/sharding/updateOne_without_shard_key/libs/write_without_shard_key_test_util.js";
const st = new ShardingTest({shards: 2, rs: {nodes: 1}});
const mongosDB = st.s0.getDB(jsTestName());
const mongosColl = mongosDB[jsTestName()];
assert.commandWorked(mongosDB.dropDatabase());
// Enable sharding on the test DB and ensure its primary is st.shard0.shardName.
assert.commandWorked(
mongosDB.adminCommand({enableSharding: mongosDB.getName(), primaryShard: st.rs0.getURL()}));
// Test that command succeeds when no internal options have been specified.
assert.commandWorked(
mongosDB.runCommand({aggregate: mongosColl.getName(), pipeline: [], cursor: {}}));
// Test that the command fails if we have 'needsMerge: false' without 'fromMongos'.
assert.commandFailedWithCode(
mongosDB.runCommand(
{aggregate: mongosColl.getName(), pipeline: [], cursor: {}, needsMerge: false}),
ErrorCodes.FailedToParse);
// Test that the command fails if we have 'needsMerge: true' without 'fromMongos'.
assert.commandFailedWithCode(
mongosDB.runCommand(
{aggregate: mongosColl.getName(), pipeline: [], cursor: {}, needsMerge: true}),
ErrorCodes.FailedToParse);
if (WriteWithoutShardKeyTestUtil.isWriteWithoutShardKeyFeatureEnabled(mongosDB)) {
// Test that the command fails if we have 'isClusterQueryWithoutShardKeyCmd: true' without
// 'fromMongos'.
assert.commandFailedWithCode(mongosDB.runCommand({
aggregate: mongosColl.getName(),
pipeline: [],
cursor: {},
$_isClusterQueryWithoutShardKeyCmd: true
}),
ErrorCodes.InvalidOptions);
// Test that the command fails if we have 'isClusterQueryWithoutShardKeyCmd: true' with
// 'fromMongos: false'.
assert.commandFailedWithCode(mongosDB.runCommand({
aggregate: mongosColl.getName(),
pipeline: [],
cursor: {},
fromMongos: false,
$_isClusterQueryWithoutShardKeyCmd: true
}),
ErrorCodes.InvalidOptions);
}
// Test that 'fromMongos: true' cannot be specified in a command sent to mongoS.
assert.commandFailedWithCode(
mongosDB.runCommand(
{aggregate: mongosColl.getName(), pipeline: [], cursor: {}, fromMongos: true}),
51089);
// Test that 'fromMongos: false' can be specified in a command sent to mongoS.
assert.commandWorked(mongosDB.runCommand(
{aggregate: mongosColl.getName(), pipeline: [], cursor: {}, fromMongos: false}));
// Test that the command fails if we have 'needsMerge: true' with 'fromMongos: false'.
assert.commandFailedWithCode(mongosDB.runCommand({
aggregate: mongosColl.getName(),
pipeline: [],
cursor: {},
needsMerge: true,
fromMongos: false
}),
51089);
// Test that the command fails if we have 'needsMerge: true' with 'fromMongos: true'.
assert.commandFailedWithCode(mongosDB.runCommand({
aggregate: mongosColl.getName(),
pipeline: [],
cursor: {},
needsMerge: true,
fromMongos: true
}),
51089);
// Test that 'needsMerge: false' can be specified in a command sent to mongoS along with
// 'fromMongos: false'.
assert.commandWorked(mongosDB.runCommand({
aggregate: mongosColl.getName(),
pipeline: [],
cursor: {},
needsMerge: false,
fromMongos: false
}));
// Test that the 'exchange' parameter cannot be specified in a command sent to mongoS.
assert.commandFailedWithCode(mongosDB.runCommand({
aggregate: mongosColl.getName(),
pipeline: [],
cursor: {},
exchange: {policy: 'roundrobin', consumers: NumberInt(2)}
}),
51028);
// Test that the command fails when all internal parameters have been specified.
assert.commandFailedWithCode(mongosDB.runCommand({
aggregate: mongosColl.getName(),
pipeline: [],
cursor: {},
needsMerge: true,
fromMongos: true,
exchange: {policy: 'roundrobin', consumers: NumberInt(2)}
}),
51028);
// Test that the command fails when all internal parameters but exchange have been specified.
assert.commandFailedWithCode(mongosDB.runCommand({
aggregate: mongosColl.getName(),
pipeline: [],
cursor: {},
needsMerge: true,
fromMongos: true
}),
51089);
st.stop();