Files
mongo/jstests/aggregation/sort_by_count_validation.js
Alya Carina Berciu 2dc41afc54 SERVER-98214 Fix invariant failure in DocumentSourceSortByCount (#30138)
GitOrigin-RevId: 4cb49af83f4885f648c2ac5779f89a607e685da1
2024-12-11 11:26:14 +00:00

34 lines
1.5 KiB
JavaScript

/**
* Validates that $sortByCount correctly validates its inputs during parsing.
*/
const coll = db.getSiblingDB(jsTestName()).coll;
coll.drop();
assert.commandFailedWithCode(
db.runCommand({aggregate: "coll", pipeline: [{$sortByCount: {}}], cursor: {}}), [40147]);
assert.commandFailedWithCode(
db.runCommand({aggregate: "coll", pipeline: [{$sortByCount: {'': "foo"}}], cursor: {}}),
[40147]);
assert.commandFailedWithCode(
db.runCommand({aggregate: "coll", pipeline: [{$sortByCount: {'$': "foo"}}], cursor: {}}),
[ErrorCodes.InvalidPipelineOperator]);
assert.commandFailedWithCode(
db.runCommand({aggregate: "coll", pipeline: [{$sortByCount: {'$a': "foo"}}], cursor: {}}),
[ErrorCodes.InvalidPipelineOperator]);
assert.commandFailedWithCode(
db.runCommand({aggregate: "coll", pipeline: [{$sortByCount: {'a': "foo"}}], cursor: {}}),
[40147]);
assert.commandFailedWithCode(
db.runCommand({aggregate: "coll", pipeline: [{$sortByCount: {'': {}}}], cursor: {}}), [40147]);
assert.commandFailedWithCode(
db.runCommand({aggregate: "coll", pipeline: [{$sortByCount: {'': ''}}], cursor: {}}), [40147]);
assert.commandFailedWithCode(
db.runCommand({aggregate: "coll", pipeline: [{$sortByCount: {'': {'': {}}}}], cursor: {}}),
[40147]);
assert.commandFailedWithCode(
db.runCommand({aggregate: "coll", pipeline: [{$sortByCount: ''}], cursor: {}}), [40148]);
assert.commandFailedWithCode(
db.runCommand({aggregate: "coll", pipeline: [{$sortByCount: '$'}], cursor: {}}), [40148]);