@@ -20,7 +20,6 @@ import type { Topology } from '../sdam/topology';
20
20
import { type Sort } from '../sort' ;
21
21
import { TimeoutContext } from '../timeout' ;
22
22
import {
23
- applyRetryableWrites ,
24
23
getTopology ,
25
24
hasAtomicOperators ,
26
25
maybeAddIdToDocuments ,
@@ -527,15 +526,15 @@ async function executeCommands(
527
526
finalOptions . checkKeys = false ;
528
527
}
529
528
530
- if ( finalOptions . retryWrites ) {
529
+ if ( bulkOperation . retryWrites ) {
531
530
if ( isUpdateBatch ( batch ) ) {
532
- finalOptions . retryWrites =
533
- finalOptions . retryWrites && ! batch . operations . some ( op => op . multi ) ;
531
+ bulkOperation . retryWrites =
532
+ bulkOperation . retryWrites && ! batch . operations . some ( op => op . multi ) ;
534
533
}
535
534
536
535
if ( isDeleteBatch ( batch ) ) {
537
- finalOptions . retryWrites =
538
- finalOptions . retryWrites && ! batch . operations . some ( op => op . limit === 0 ) ;
536
+ bulkOperation . retryWrites =
537
+ bulkOperation . retryWrites && ! batch . operations . some ( op => op . limit === 0 ) ;
539
538
}
540
539
}
541
540
@@ -859,13 +858,16 @@ export abstract class BulkOperationBase {
859
858
s : BulkOperationPrivate ;
860
859
operationId ?: number ;
861
860
private collection : Collection ;
861
+ /** @internal */
862
+ retryWrites ?: boolean ;
862
863
863
864
/**
864
865
* Create a new OrderedBulkOperation or UnorderedBulkOperation instance
865
866
* @internal
866
867
*/
867
868
constructor ( collection : Collection , options : BulkWriteOptions , isOrdered : boolean ) {
868
869
this . collection = collection ;
870
+ this . retryWrites = collection . db . options ?. retryWrites ;
869
871
// determine whether bulkOperation is ordered or unordered
870
872
this . isOrdered = isOrdered ;
871
873
@@ -898,10 +900,6 @@ export abstract class BulkOperationBase {
898
900
// + 1 bytes for null terminator
899
901
const maxKeySize = ( maxWriteBatchSize - 1 ) . toString ( 10 ) . length + 2 ;
900
902
901
- // Final options for retryable writes
902
- let finalOptions = Object . assign ( { } , options ) ;
903
- finalOptions = applyRetryableWrites ( finalOptions , collection . db ) ;
904
-
905
903
// Final results
906
904
const bulkResult : BulkResult = {
907
905
ok : 1 ,
@@ -943,7 +941,7 @@ export abstract class BulkOperationBase {
943
941
// Topology
944
942
topology,
945
943
// Options
946
- options : finalOptions ,
944
+ options : options ,
947
945
// BSON options
948
946
bsonOptions : resolveBSONOptions ( options ) ,
949
947
// Current operation
0 commit comments