(
bulkOperation: BulkOperationBase,
options: BulkWriteOptions & { timeoutContext?: TimeoutContext | null }
)
| 499 | } |
| 500 | |
| 501 | async function executeCommands( |
| 502 | bulkOperation: BulkOperationBase, |
| 503 | options: BulkWriteOptions & { timeoutContext?: TimeoutContext | null } |
| 504 | ): Promise<BulkWriteResult> { |
| 505 | if (bulkOperation.s.batches.length === 0) { |
| 506 | return new BulkWriteResult(bulkOperation.s.bulkResult, bulkOperation.isOrdered); |
| 507 | } |
| 508 | |
| 509 | for (const batch of bulkOperation.s.batches) { |
| 510 | const finalOptions = resolveOptions(bulkOperation, { |
| 511 | ...options, |
| 512 | ordered: bulkOperation.isOrdered |
| 513 | }); |
| 514 | |
| 515 | if (finalOptions.bypassDocumentValidation !== true) { |
| 516 | delete finalOptions.bypassDocumentValidation; |
| 517 | } |
| 518 | |
| 519 | // Is the bypassDocumentValidation options specific |
| 520 | if (bulkOperation.s.bypassDocumentValidation === true) { |
| 521 | finalOptions.bypassDocumentValidation = true; |
| 522 | } |
| 523 | |
| 524 | // Is the checkKeys option disabled |
| 525 | if (bulkOperation.s.checkKeys === false) { |
| 526 | finalOptions.checkKeys = false; |
| 527 | } |
| 528 | |
| 529 | if (bulkOperation.retryWrites) { |
| 530 | if (isUpdateBatch(batch)) { |
| 531 | bulkOperation.retryWrites = |
| 532 | bulkOperation.retryWrites && !batch.operations.some(op => op.multi); |
| 533 | } |
| 534 | |
| 535 | if (isDeleteBatch(batch)) { |
| 536 | bulkOperation.retryWrites = |
| 537 | bulkOperation.retryWrites && !batch.operations.some(op => op.limit === 0); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | const operation = isInsertBatch(batch) |
| 542 | ? new InsertOperation(bulkOperation.s.namespace, batch.operations, finalOptions) |
| 543 | : isUpdateBatch(batch) |
| 544 | ? new UpdateOperation(bulkOperation.s.namespace, batch.operations, finalOptions) |
| 545 | : isDeleteBatch(batch) |
| 546 | ? new DeleteOperation(bulkOperation.s.namespace, batch.operations, finalOptions) |
| 547 | : null; |
| 548 | |
| 549 | if (operation == null) throw new MongoRuntimeError(`Unknown batchType: ${batch.batchType}`); |
| 550 | |
| 551 | let thrownError = null; |
| 552 | let result; |
| 553 | try { |
| 554 | result = await executeOperation( |
| 555 | bulkOperation.s.collection.client, |
| 556 | operation, |
| 557 | finalOptions.timeoutContext |
| 558 | ); |
no test coverage detected