@@ -20,7 +20,6 @@ import type { Topology } from '../sdam/topology';
2020import { type Sort } from '../sort' ;
2121import { TimeoutContext } from '../timeout' ;
2222import {
23- applyRetryableWrites ,
2423 getTopology ,
2524 hasAtomicOperators ,
2625 maybeAddIdToDocuments ,
@@ -527,15 +526,15 @@ async function executeCommands(
527526 finalOptions . checkKeys = false ;
528527 }
529528
530- if ( finalOptions . retryWrites ) {
529+ if ( bulkOperation . retryWrites ) {
531530 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 ) ;
534533 }
535534
536535 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 ) ;
539538 }
540539 }
541540
@@ -859,13 +858,16 @@ export abstract class BulkOperationBase {
859858 s : BulkOperationPrivate ;
860859 operationId ?: number ;
861860 private collection : Collection ;
861+ /** @internal */
862+ retryWrites ?: boolean ;
862863
863864 /**
864865 * Create a new OrderedBulkOperation or UnorderedBulkOperation instance
865866 * @internal
866867 */
867868 constructor ( collection : Collection , options : BulkWriteOptions , isOrdered : boolean ) {
868869 this . collection = collection ;
870+ this . retryWrites = collection . db . options ?. retryWrites ;
869871 // determine whether bulkOperation is ordered or unordered
870872 this . isOrdered = isOrdered ;
871873
@@ -898,10 +900,6 @@ export abstract class BulkOperationBase {
898900 // + 1 bytes for null terminator
899901 const maxKeySize = ( maxWriteBatchSize - 1 ) . toString ( 10 ) . length + 2 ;
900902
901- // Final options for retryable writes
902- let finalOptions = Object . assign ( { } , options ) ;
903- finalOptions = applyRetryableWrites ( finalOptions , collection . db ) ;
904-
905903 // Final results
906904 const bulkResult : BulkResult = {
907905 ok : 1 ,
@@ -943,7 +941,7 @@ export abstract class BulkOperationBase {
943941 // Topology
944942 topology,
945943 // Options
946- options : finalOptions ,
944+ options : options ,
947945 // BSON options
948946 bsonOptions : resolveBSONOptions ( options ) ,
949947 // Current operation
0 commit comments