Skip to content

Commit

Permalink
fix(bulk): fixing retryable writes for mass-change ops
Browse files Browse the repository at this point in the history
updateMany and deleteMany should not be retryable.
  • Loading branch information
daprahamian authored and mbroadst committed Jun 1, 2018
1 parent 4ba5adc commit 0604036
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/bulk/ordered.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions lib/bulk/unordered.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0604036

Please sign in to comment.