Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shell-api): Add support for running aggregate database with a single stage MONGOSH-1868 #2218

Merged
merged 8 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/shell-api/src/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ describe('Database', function () {
);
});

it('supports a single aggregation stage', async function () {
await database.aggregate({ $piplelineStage: {} }, { options: true });

expect(serviceProvider.aggregateDb).to.have.been.calledWith(
database._name,
[{ $piplelineStage: {} }],
{ options: true }
);
});

it('calls serviceProvider.aggregateDb with explicit batchSize', async function () {
await database.aggregate([{ $piplelineStage: {} }], {
options: true,
Expand Down
8 changes: 7 additions & 1 deletion packages/shell-api/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,20 @@ export default class Database extends ShellApiWithMongoClass {
@returnType('AggregationCursor')
@apiVersions([1])
async aggregate(
pipeline: Document[],
pipelineOrSingleStage: Document | Document[],
options?: Document
): Promise<AggregationCursor> {
if ('background' in (options ?? {})) {
await this._instanceState.printWarning(
aggregateBackgroundOptionNotSupportedHelp
);
}
const pipeline: Document[] = Array.isArray(pipelineOrSingleStage)
? pipelineOrSingleStage
: [pipelineOrSingleStage];

assertArgsDefinedType([pipeline], [true], 'Database.aggregate');

this._emitDatabaseApiCall('aggregate', { options, pipeline });

const { aggOptions, dbOptions, explain } = adaptAggregateOptions(options);
Expand Down Expand Up @@ -1429,6 +1434,7 @@ export default class Database extends ShellApiWithMongoClass {
CommonErrors.CommandFailed
);
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
gagik marked this conversation as resolved.
Show resolved Hide resolved
for (const cmdDescription of Object.values(result.commands) as Document[]) {
if ('slaveOk' in cmdDescription) {
cmdDescription.secondaryOk = cmdDescription.slaveOk;
Expand Down
Loading