rename.js 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.RenameOperation = void 0;
  4. const collection_1 = require("../collection");
  5. const utils_1 = require("../utils");
  6. const command_1 = require("./command");
  7. const operation_1 = require("./operation");
  8. /** @internal */
  9. class RenameOperation extends command_1.CommandOperation {
  10. constructor(collection, newName, options) {
  11. super(collection, options);
  12. this.collection = collection;
  13. this.newName = newName;
  14. this.options = options;
  15. this.ns = new utils_1.MongoDBNamespace('admin', '$cmd');
  16. }
  17. async execute(server, session) {
  18. // Build the command
  19. const renameCollection = this.collection.namespace;
  20. const toCollection = this.collection.s.namespace.withCollection(this.newName).toString();
  21. const dropTarget = typeof this.options.dropTarget === 'boolean' ? this.options.dropTarget : false;
  22. const command = {
  23. renameCollection: renameCollection,
  24. to: toCollection,
  25. dropTarget: dropTarget
  26. };
  27. await super.executeCommand(server, session, command);
  28. return new collection_1.Collection(this.collection.s.db, this.newName, this.collection.s.options);
  29. }
  30. }
  31. exports.RenameOperation = RenameOperation;
  32. (0, operation_1.defineAspects)(RenameOperation, [operation_1.Aspect.WRITE_OPERATION]);
  33. //# sourceMappingURL=rename.js.map