@@ -1940,6 +1940,48 @@ describe('Bulk', function () {
1940
1940
} )
1941
1941
} ) ;
1942
1942
1943
+ it ( 'should apply arrayFilters to bulk updates via FindOperators' , {
1944
+ metadata : { requires : { mongodb : '>= 3.6' } } ,
1945
+ test : withMonitoredClient ( [ 'update' , 'delete' ] , function ( client , events , done ) {
1946
+ client . db ( ) . dropCollection ( 'bulkArrayFilters' , ( ) => {
1947
+ const coll = client . db ( ) . collection ( 'bulkArrayFilters' ) ;
1948
+ const bulk = coll . initializeOrderedBulkOp ( ) ;
1949
+
1950
+ bulk . insert ( { person : 'Foo' , scores : [ 4 , 9 , 12 ] } ) ;
1951
+ bulk . insert ( { person : 'Bar' , scores : [ 13 , 0 , 52 ] } ) ;
1952
+ bulk
1953
+ . find ( { scores : { $lt : 1 } } )
1954
+ . arrayFilters ( [ { e : { $lt : 1 } } ] )
1955
+ . updateOne ( { $set : { 'scores.$[e]' : 1 } } ) ;
1956
+ bulk
1957
+ . find ( { scores : { $gte : 10 } } )
1958
+ . arrayFilters ( [ { e : { $gte : 10 } } ] )
1959
+ . update ( { $set : { 'scores.$[e]' : 10 } } ) ;
1960
+
1961
+ bulk . execute ( err => {
1962
+ expect ( err ) . to . not . exist ;
1963
+ expect ( events ) . to . be . an ( 'array' ) . with . lengthOf ( 1 ) ;
1964
+ expect ( events [ 0 ] ) . to . have . property ( 'commandName' , 'update' ) ;
1965
+ const updateCommand = events [ 0 ] . command ;
1966
+ expect ( updateCommand ) . property ( 'updates' ) . to . be . an ( 'array' ) . with . lengthOf ( 2 ) ;
1967
+ updateCommand . updates . forEach ( update => expect ( update ) . to . have . property ( 'arrayFilters' ) ) ;
1968
+ coll . find ( { } ) . toArray ( ( err , result ) => {
1969
+ expect ( err ) . to . not . exist ;
1970
+ expect ( result [ 0 ] ) . to . containSubset ( {
1971
+ person : 'Foo' ,
1972
+ scores : [ 4 , 9 , 10 ]
1973
+ } ) ;
1974
+ expect ( result [ 1 ] ) . to . containSubset ( {
1975
+ person : 'Bar' ,
1976
+ scores : [ 10 , 1 , 10 ]
1977
+ } ) ;
1978
+ client . close ( done ) ;
1979
+ } ) ;
1980
+ } ) ;
1981
+ } ) ;
1982
+ } )
1983
+ } ) ;
1984
+
1943
1985
it ( 'should throw an error if raw operations are passed to bulkWrite' , function ( ) {
1944
1986
const client = this . configuration . newClient ( ) ;
1945
1987
return client . connect ( ) . then ( ( ) => {
0 commit comments