Skip to content

Commit af04244

Browse files
gagikaddaleax
andauthored
fix(shell-api): Add support for running aggregate database with a single stage MONGOSH-1868 (#2218)
Co-authored-by: Anna Henningsen <anna.henningsen@mongodb.com>
1 parent a08940b commit af04244

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/shell-api/src/database.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,16 @@ describe('Database', function () {
400400
);
401401
});
402402

403+
it('supports a single aggregation stage', async function () {
404+
await database.aggregate({ $piplelineStage: {} }, { options: true });
405+
406+
expect(serviceProvider.aggregateDb).to.have.been.calledWith(
407+
database._name,
408+
[{ $piplelineStage: {} }],
409+
{ options: true }
410+
);
411+
});
412+
403413
it('calls serviceProvider.aggregateDb with explicit batchSize', async function () {
404414
await database.aggregate([{ $piplelineStage: {} }], {
405415
options: true,

packages/shell-api/src/database.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,20 @@ export default class Database extends ShellApiWithMongoClass {
423423
@returnType('AggregationCursor')
424424
@apiVersions([1])
425425
async aggregate(
426-
pipeline: Document[],
426+
pipelineOrSingleStage: Document | Document[],
427427
options?: Document
428428
): Promise<AggregationCursor> {
429429
if ('background' in (options ?? {})) {
430430
await this._instanceState.printWarning(
431431
aggregateBackgroundOptionNotSupportedHelp
432432
);
433433
}
434+
const pipeline: Document[] = Array.isArray(pipelineOrSingleStage)
435+
? pipelineOrSingleStage
436+
: [pipelineOrSingleStage];
437+
434438
assertArgsDefinedType([pipeline], [true], 'Database.aggregate');
439+
435440
this._emitDatabaseApiCall('aggregate', { options, pipeline });
436441

437442
const { aggOptions, dbOptions, explain } = adaptAggregateOptions(options);
@@ -1429,6 +1434,7 @@ export default class Database extends ShellApiWithMongoClass {
14291434
CommonErrors.CommandFailed
14301435
);
14311436
}
1437+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
14321438
for (const cmdDescription of Object.values(result.commands) as Document[]) {
14331439
if ('slaveOk' in cmdDescription) {
14341440
cmdDescription.secondaryOk = cmdDescription.slaveOk;

0 commit comments

Comments
 (0)