diff --git a/lib/bulk/ordered.js b/lib/bulk/ordered.js index bbfaf2fc22..dcf01d1c5b 100644 --- a/lib/bulk/ordered.js +++ b/lib/bulk/ordered.js @@ -515,6 +515,17 @@ var executeCommands = function(self, options, callback) { finalOptions.checkKeys = false; } + if (finalOptions.retryWrites) { + if (batch.batchType === common.UPDATE) { + finalOptions.retryWrites = finalOptions.retryWrites && !batch.operations.some(op => op.multi); + } + + if (batch.batchType === common.REMOVE) { + finalOptions.retryWrites = + finalOptions.retryWrites && !batch.operations.some(op => op.limit === 0); + } + } + try { if (batch.batchType === common.INSERT) { self.s.topology.insert( diff --git a/lib/bulk/unordered.js b/lib/bulk/unordered.js index 15491df10f..68bd1cf05f 100644 --- a/lib/bulk/unordered.js +++ b/lib/bulk/unordered.js @@ -476,6 +476,17 @@ var executeBatch = function(self, batch, options, callback) { finalOptions.checkKeys = false; } + if (finalOptions.retryWrites) { + if (batch.batchType === common.UPDATE) { + finalOptions.retryWrites = finalOptions.retryWrites && !batch.operations.some(op => op.multi); + } + + if (batch.batchType === common.REMOVE) { + finalOptions.retryWrites = + finalOptions.retryWrites && !batch.operations.some(op => op.limit === 0); + } + } + try { if (batch.batchType === common.INSERT) { self.s.topology.insert(