rename.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.RenameOperation = void 0;
  4. const responses_1 = require("../cmap/wire_protocol/responses");
  5. const collection_1 = require("../collection");
  6. const utils_1 = require("../utils");
  7. const command_1 = require("./command");
  8. const operation_1 = require("./operation");
  9. /** @internal */
  10. class RenameOperation extends command_1.CommandOperation {
  11. constructor(collection, newName, options) {
  12. super(collection, options);
  13. this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
  14. this.collection = collection;
  15. this.newName = newName;
  16. this.options = options;
  17. this.ns = new utils_1.MongoDBNamespace('admin', '$cmd');
  18. }
  19. get commandName() {
  20. return 'renameCollection';
  21. }
  22. buildCommandDocument(_connection, _session) {
  23. const renameCollection = this.collection.namespace;
  24. const to = this.collection.s.namespace.withCollection(this.newName).toString();
  25. const dropTarget = typeof this.options.dropTarget === 'boolean' ? this.options.dropTarget : false;
  26. return {
  27. renameCollection,
  28. to,
  29. dropTarget
  30. };
  31. }
  32. handleOk(_response) {
  33. return new collection_1.Collection(this.collection.db, this.newName, this.collection.s.options);
  34. }
  35. }
  36. exports.RenameOperation = RenameOperation;
  37. (0, operation_1.defineAspects)(RenameOperation, [operation_1.Aspect.WRITE_OPERATION]);
  38. //# sourceMappingURL=rename.js.map