Uname: Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
Software: LiteSpeed
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.213.251.212
Your Ip: 3.147.80.179
User: allssztx (535) | Group: allssztx (533)
Safe Mode: OFF
Disable Function:
NONE

name : rename.ts
import type { Document } from '../bson';
import { Collection } from '../collection';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { type TimeoutContext } from '../timeout';
import { MongoDBNamespace } from '../utils';
import { CommandOperation, type CommandOperationOptions } from './command';
import { Aspect, defineAspects } from './operation';

/** @public */
export interface RenameOptions extends CommandOperationOptions {
  /** Drop the target name collection if it previously exists. */
  dropTarget?: boolean;
  /** Unclear */
  new_collection?: boolean;
}

/** @internal */
export class RenameOperation extends CommandOperation<Document> {
  constructor(
    public collection: Collection,
    public newName: string,
    public override options: RenameOptions
  ) {
    super(collection, options);
    this.ns = new MongoDBNamespace('admin', '$cmd');
  }

  override get commandName(): string {
    return 'renameCollection' as const;
  }

  override async execute(
    server: Server,
    session: ClientSession | undefined,
    timeoutContext: TimeoutContext
  ): Promise<Collection> {
    // Build the command
    const renameCollection = this.collection.namespace;
    const toCollection = this.collection.s.namespace.withCollection(this.newName).toString();
    const dropTarget =
      typeof this.options.dropTarget === 'boolean' ? this.options.dropTarget : false;

    const command = {
      renameCollection: renameCollection,
      to: toCollection,
      dropTarget: dropTarget
    };

    await super.executeCommand(server, session, command, timeoutContext);
    return new Collection(this.collection.s.db, this.newName, this.collection.s.options);
  }
}

defineAspects(RenameOperation, [Aspect.WRITE_OPERATION]);
© 2025 GrazzMean-Shell