@@ -435,7 +435,7 @@ describe('ReadConcern', function() {
435
435
} ) ;
436
436
437
437
it ( 'Should set majority readConcern aggregate command but ignore due to out' , {
438
- metadata : { requires : { topology : 'replicaset' , mongodb : '>= 3.2' } } ,
438
+ metadata : { requires : { topology : 'replicaset' , mongodb : '>= 3.2 < 4.1 ' } } ,
439
439
440
440
test : function ( done ) {
441
441
var listener = require ( '../..' ) . instrument ( function ( err ) {
@@ -500,6 +500,64 @@ describe('ReadConcern', function() {
500
500
}
501
501
} ) ;
502
502
503
+ it ( 'Should set majority readConcern aggregate command against server >= 4.1' , {
504
+ metadata : { requires : { topology : 'replicaset' , mongodb : '>= 4.1' } } ,
505
+
506
+ test : function ( done ) {
507
+ // Contains all the apm events
508
+ const started = [ ] ;
509
+ const succeeded = [ ] ;
510
+ // Get a new instance
511
+ const client = this . configuration . newClient (
512
+ { w : 1 } ,
513
+ { poolSize : 1 , readConcern : { level : 'majority' } , monitorCommands : true }
514
+ ) ;
515
+
516
+ client
517
+ . connect ( )
518
+ . then ( ( ) => {
519
+ // Get a collection
520
+ const collection = client
521
+ . db ( this . configuration . db )
522
+ . collection ( 'readConcernCollectionAggregate1' ) ;
523
+
524
+ // Listen to apm events
525
+ client . on ( 'commandStarted' , event => {
526
+ if ( event . commandName === 'aggregate' ) started . push ( event ) ;
527
+ } ) ;
528
+ client . on ( 'commandSucceeded' , event => {
529
+ if ( event . commandName === 'aggregate' ) succeeded . push ( event ) ;
530
+ } ) ;
531
+
532
+ // Execute find
533
+ return collection
534
+ . aggregate ( [ { $match : { } } , { $out : 'readConcernCollectionAggregate1Output' } ] )
535
+ . toArray ( )
536
+ . then ( ( ) => {
537
+ expect ( started ) . to . have . a . lengthOf ( 1 ) ;
538
+ expect ( started [ 0 ] ) . to . have . property ( 'commandName' , 'aggregate' ) ;
539
+ expect ( succeeded [ 0 ] ) . to . have . property ( 'commandName' , 'aggregate' ) ;
540
+ expect ( started [ 0 ] ) . to . have . nested . property ( 'command.readConcern.level' , 'majority' ) ;
541
+
542
+ // Execute find
543
+ return collection
544
+ . aggregate ( [ { $match : { } } ] , { out : 'readConcernCollectionAggregate2Output' } )
545
+ . toArray ( )
546
+ . then ( ( ) => {
547
+ expect ( started ) . to . have . a . lengthOf ( 2 ) ;
548
+ expect ( started [ 1 ] ) . to . have . property ( 'commandName' , 'aggregate' ) ;
549
+ expect ( succeeded [ 1 ] ) . to . have . property ( 'commandName' , 'aggregate' ) ;
550
+ expect ( started [ 1 ] ) . to . have . nested . property (
551
+ 'command.readConcern.level' ,
552
+ 'majority'
553
+ ) ;
554
+ } ) ;
555
+ } ) ;
556
+ } )
557
+ . then ( ( ) => client . close ( done ) , e => client . close ( ( ) => done ( e ) ) ) ;
558
+ }
559
+ } ) ;
560
+
503
561
it ( 'Should set majority readConcern mapReduce command but be ignored' , {
504
562
metadata : { requires : { topology : 'replicaset' , mongodb : '>= 3.2' } } ,
505
563
0 commit comments