@@ -1688,6 +1688,51 @@ describe('Bulk', function () {
1688
1688
}
1689
1689
} ) ;
1690
1690
1691
+ it ( 'should apply hint via FindOperators' , {
1692
+ metadata : { requires : { mongodb : '>= 4.4' } } ,
1693
+ async test ( ) {
1694
+ const bulk = client . db ( ) . collection ( 'coll' ) . initializeOrderedBulkOp ( ) ;
1695
+
1696
+ const events = [ ] ;
1697
+ client . on ( 'commandStarted' , event => {
1698
+ if ( [ 'update' , 'delete' ] . includes ( event . commandName ) ) {
1699
+ events . push ( event ) ;
1700
+ }
1701
+ } ) ;
1702
+
1703
+ // updates
1704
+ bulk
1705
+ . find ( { b : 1 } )
1706
+ . hint ( { b : 1 } )
1707
+ . updateOne ( { $set : { b : 2 } } ) ;
1708
+ bulk
1709
+ . find ( { b : 2 } )
1710
+ . hint ( { b : 1 } )
1711
+ . update ( { $set : { b : 3 } } ) ;
1712
+ bulk . find ( { b : 3 } ) . hint ( { b : 1 } ) . replaceOne ( { b : 2 } ) ;
1713
+
1714
+ // deletes
1715
+ bulk . find ( { b : 2 } ) . hint ( { b : 1 } ) . deleteOne ( ) ;
1716
+ bulk . find ( { b : 1 } ) . hint ( { b : 1 } ) . delete ( ) ;
1717
+
1718
+ await bulk . execute ( ) ;
1719
+
1720
+ expect ( events ) . to . be . an ( 'array' ) . with . length . at . least ( 1 ) ;
1721
+ expect ( events [ 0 ] ) . property ( 'commandName' ) . to . equal ( 'update' ) ;
1722
+ const updateCommand = events [ 0 ] . command ;
1723
+ expect ( updateCommand ) . property ( 'updates' ) . to . be . an ( 'array' ) . with . length ( 3 ) ;
1724
+ updateCommand . updates . forEach ( statement => {
1725
+ expect ( statement ) . property ( 'hint' ) . to . eql ( { b : 1 } ) ;
1726
+ } ) ;
1727
+ expect ( events [ 1 ] ) . property ( 'commandName' ) . to . equal ( 'delete' ) ;
1728
+ const deleteCommand = events [ 1 ] . command ;
1729
+ expect ( deleteCommand ) . property ( 'deletes' ) . to . be . an ( 'array' ) . with . length ( 2 ) ;
1730
+ deleteCommand . deletes . forEach ( statement => {
1731
+ expect ( statement ) . property ( 'hint' ) . to . eql ( { b : 1 } ) ;
1732
+ } ) ;
1733
+ }
1734
+ } ) ;
1735
+
1691
1736
it ( 'should apply arrayFilters to bulk updates via FindOperators' , {
1692
1737
metadata : { requires : { mongodb : '>= 3.6' } } ,
1693
1738
test : function ( done ) {
@@ -1737,6 +1782,24 @@ describe('Bulk', function () {
1737
1782
}
1738
1783
} ) ;
1739
1784
1785
+ it ( 'should accept pipeline-style updates' , {
1786
+ metadata : { requires : { mongodb : '>= 4.2' } } ,
1787
+ async test ( ) {
1788
+ const coll = client . db ( ) . collection ( 'coll' ) ;
1789
+ const bulk = coll . initializeOrderedBulkOp ( ) ;
1790
+
1791
+ coll . insertMany ( [ { a : 1 } , { a : 2 } ] ) ;
1792
+
1793
+ bulk . find ( { a : 1 } ) . updateOne ( [ { $project : { a : { $add : [ '$a' , 10 ] } } } ] ) ;
1794
+ bulk . find ( { a : 2 } ) . update ( [ { $project : { a : { $add : [ '$a' , 100 ] } } } ] ) ;
1795
+
1796
+ await bulk . execute ( ) ;
1797
+
1798
+ const contents = await coll . find ( ) . project ( { _id : 0 } ) . toArray ( ) ;
1799
+ expect ( contents ) . to . deep . equal ( [ { a : 11 } , { a : 102 } ] ) ;
1800
+ }
1801
+ } ) ;
1802
+
1740
1803
it ( 'should throw an error if raw operations are passed to bulkWrite' , function ( ) {
1741
1804
const coll = client . db ( ) . collection ( 'single_bulk_write_error' ) ;
1742
1805
return coll
0 commit comments