File tree Expand file tree Collapse file tree 2 files changed +22
-11
lines changed
Expand file tree Collapse file tree 2 files changed +22
-11
lines changed Original file line number Diff line number Diff line change @@ -390,19 +390,18 @@ describe('Database', function () {
390390 serviceProviderCursor = stubInterface < ServiceProviderAggCursor > ( ) ;
391391 } ) ;
392392
393- it ( 'throws if the given argument is not an array' , async function ( ) {
394- let caughtError : MongoshInvalidInputError | undefined ;
395- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
396- await database . aggregate ( { } as any ) . catch ( ( err ) => {
397- caughtError = err ;
398- } ) ;
399- expect ( caughtError ?. message ) . contains (
400- 'Aggregate pipeline argument must be an array'
393+ it ( 'calls serviceProvider.aggregateDb with pipleline and options' , async function ( ) {
394+ await database . aggregate ( [ { $piplelineStage : { } } ] , { options : true } ) ;
395+
396+ expect ( serviceProvider . aggregateDb ) . to . have . been . calledWith (
397+ database . _name ,
398+ [ { $piplelineStage : { } } ] ,
399+ { options : true }
401400 ) ;
402401 } ) ;
403402
404- it ( 'calls serviceProvider.aggregateDb with pipleline and options ' , async function ( ) {
405- await database . aggregate ( [ { $piplelineStage : { } } ] , { options : true } ) ;
403+ it ( 'supports a single aggregation stage ' , async function ( ) {
404+ await database . aggregate ( { $piplelineStage : { } } , { options : true } ) ;
406405
407406 expect ( serviceProvider . aggregateDb ) . to . have . been . calledWith (
408407 database . _name ,
Original file line number Diff line number Diff line change @@ -412,6 +412,14 @@ export default class Database extends ShellApiWithMongoClass {
412412 return await this . _runAdminCommand ( cmd , { } ) ;
413413 }
414414
415+ async aggregate (
416+ singleStage : Document ,
417+ options ?: Document
418+ ) : Promise < AggregationCursor > ;
419+ async aggregate (
420+ pipeline : Document [ ] ,
421+ options ?: Document
422+ ) : Promise < AggregationCursor > ;
415423 /**
416424 * Run an aggregation against the db.
417425 *
@@ -423,14 +431,18 @@ export default class Database extends ShellApiWithMongoClass {
423431 @returnType ( 'AggregationCursor' )
424432 @apiVersions ( [ 1 ] )
425433 async aggregate (
426- pipeline : Document [ ] ,
434+ pipelineOrSingleStage : Document | Document [ ] ,
427435 options ?: Document
428436 ) : Promise < AggregationCursor > {
429437 if ( 'background' in ( options ?? { } ) ) {
430438 await this . _instanceState . printWarning (
431439 aggregateBackgroundOptionNotSupportedHelp
432440 ) ;
433441 }
442+ const pipeline : Document [ ] = Array . isArray ( pipelineOrSingleStage )
443+ ? pipelineOrSingleStage
444+ : [ pipelineOrSingleStage ] ;
445+
434446 assertArgsDefinedType ( [ pipeline ] , [ true ] , 'Database.aggregate' ) ;
435447
436448 if ( ! Array . isArray ( pipeline ) ) {
You can’t perform that action at this time.
0 commit comments