bulk_write.js 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.BulkWriteOperation = void 0;
  4. const operation_1 = require("./operation");
  5. /** @internal */
  6. class BulkWriteOperation extends operation_1.AbstractOperation {
  7. constructor(collection, operations, options) {
  8. super(options);
  9. this.options = options;
  10. this.collection = collection;
  11. this.operations = operations;
  12. }
  13. async execute(server, session) {
  14. const coll = this.collection;
  15. const operations = this.operations;
  16. const options = { ...this.options, ...this.bsonOptions, readPreference: this.readPreference };
  17. // Create the bulk operation
  18. const bulk = options.ordered === false
  19. ? coll.initializeUnorderedBulkOp(options)
  20. : coll.initializeOrderedBulkOp(options);
  21. // for each op go through and add to the bulk
  22. for (let i = 0; i < operations.length; i++) {
  23. bulk.raw(operations[i]);
  24. }
  25. // Execute the bulk
  26. const result = await bulk.execute({ ...options, session });
  27. return result;
  28. }
  29. }
  30. exports.BulkWriteOperation = BulkWriteOperation;
  31. (0, operation_1.defineAspects)(BulkWriteOperation, [operation_1.Aspect.WRITE_OPERATION]);
  32. //# sourceMappingURL=bulk_write.js.map