Skip to content

Commit 653be86

Browse files
committed
fix: check if retryable
1 parent 042934c commit 653be86

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/operations/client_bulk_write/client_bulk_write.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export class ClientBulkWriteOperation extends CommandOperation<ClientBulkWriteCu
3131
return this.commandBuilder.resetBatch();
3232
}
3333

34+
override get canRetryWrite(): boolean {
35+
return this.commandBuilder.isRetryable && super.canRetryWrite;
36+
}
37+
3438
/**
3539
* Execute the command. Superclass will handle write concern, etc.
3640
* @param server - The server.

src/operations/client_bulk_write/command_builder.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class ClientBulkWriteCommandBuilder {
4242
currentModelIndex: number;
4343
previousModelIndex: number;
4444
lastOperations: Document[];
45+
isRetryable: boolean;
4546

4647
/**
4748
* Create the command builder.
@@ -58,6 +59,10 @@ export class ClientBulkWriteCommandBuilder {
5859
this.currentModelIndex = 0;
5960
this.previousModelIndex = 0;
6061
this.lastOperations = [];
62+
// Multi updates are not retryable.
63+
this.isRetryable = !models.some(model => {
64+
return model.name === 'deleteMany' || model.name === 'updateMany';
65+
});
6166
}
6267

6368
/**

src/operations/client_bulk_write/results_merger.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export class ClientBulkWriteResultsMerger {
7070
// record the error in writeErrors and immediately throw the exception. Otherwise, drivers
7171
// MUST continue to iterate the results cursor and execute any further bulkWrite batches.
7272
if (this.options.ordered) {
73-
console.log(document);
7473
const error = new MongoClientBulkWriteError({
7574
message: 'Mongo client ordered bulk write encountered a write error.'
7675
});

0 commit comments

Comments
 (0)