File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments