@@ -1637,9 +1637,9 @@ describe('Bulk', function() {
1637
1637
coll . bulkWrite (
1638
1638
[
1639
1639
{ insertOne : { _id : 5 , a : 0 } } ,
1640
- { updateOne : { filter : { _id : 1 } , update : { $set : { a : 0 } } } } ,
1640
+ { updateOne : { filter : { _id : 1 } , update : { $set : { a : 15 } } } } ,
1641
1641
{ insertOne : { _id : 6 , a : 0 } } ,
1642
- { updateOne : { filter : { _id : 2 } , update : { $set : { a : 0 } } } }
1642
+ { updateOne : { filter : { _id : 2 } , update : { $set : { a : 42 } } } }
1643
1643
] ,
1644
1644
{ ordered : false }
1645
1645
)
@@ -1666,7 +1666,7 @@ describe('Bulk', function() {
1666
1666
return client . connect ( ) . then ( ( ) => {
1667
1667
this . defer ( ( ) => client . close ( ) ) ;
1668
1668
1669
- const coll = client . db ( ) . collection ( 'bulk_op_ordering_test ' ) ;
1669
+ const coll = client . db ( ) . collection ( 'unordered_preserve_order ' ) ;
1670
1670
function ignoreNsNotFound ( err ) {
1671
1671
if ( ! err . message . match ( / n s n o t f o u n d / ) ) throw err ;
1672
1672
}
@@ -1697,4 +1697,70 @@ describe('Bulk', function() {
1697
1697
) ;
1698
1698
} ) ;
1699
1699
} ) ;
1700
+
1701
+ it ( 'should not fail on the first error in an unorderd bulkWrite' , function ( ) {
1702
+ const client = this . configuration . newClient ( ) ;
1703
+ return client . connect ( ) . then ( ( ) => {
1704
+ this . defer ( ( ) => client . close ( ) ) ;
1705
+
1706
+ const coll = client . db ( ) . collection ( 'bulk_op_ordering_test' ) ;
1707
+ function ignoreNsNotFound ( err ) {
1708
+ if ( ! err . message . match ( / n s n o t f o u n d / ) ) throw err ;
1709
+ }
1710
+
1711
+ return coll
1712
+ . drop ( )
1713
+ . catch ( ignoreNsNotFound )
1714
+ . then ( ( ) => coll . createIndex ( { email : 1 } , { unique : 1 , background : false } ) )
1715
+ . then ( ( ) =>
1716
+ Promise . all ( [
1717
+ coll . updateOne (
1718
+ { email : 'adam@gmail.com' } ,
1719
+ { $set : { name : 'Adam Smith' , age : 29 } } ,
1720
+ { upsert : true }
1721
+ ) ,
1722
+ coll . updateOne (
1723
+ { email : 'john@gmail.com' } ,
1724
+ { $set : { name : 'John Doe' , age : 32 } } ,
1725
+ { upsert : true }
1726
+ )
1727
+ ] )
1728
+ )
1729
+ . then ( ( ) =>
1730
+ coll . bulkWrite (
1731
+ [
1732
+ {
1733
+ updateOne : {
1734
+ filter : { email : 'adam@gmail.com' } ,
1735
+ update : { $set : { age : 39 } }
1736
+ }
1737
+ } ,
1738
+ {
1739
+ insertOne : {
1740
+ document : {
1741
+ email : 'john@gmail.com'
1742
+ }
1743
+ }
1744
+ }
1745
+ ] ,
1746
+ { ordered : false }
1747
+ )
1748
+ )
1749
+ . then (
1750
+ ( ) => {
1751
+ throw new Error ( 'expected a bulk error' ) ;
1752
+ } ,
1753
+ err =>
1754
+ expect ( err )
1755
+ . property ( 'code' )
1756
+ . to . equal ( 11000 )
1757
+ )
1758
+ . then ( ( ) => coll . findOne ( { email : 'adam@gmail.com' } ) )
1759
+ . then ( updatedAdam =>
1760
+ expect ( updatedAdam )
1761
+ . property ( 'age' )
1762
+ . to . equal ( 39 )
1763
+ ) ;
1764
+ } ) ;
1765
+ } ) ;
1700
1766
} ) ;
0 commit comments