CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
drop.ts59 linesDownload Raw Back to search_indexes
1import { type Connection, type MongoError } from '../..';2import type { Document } from '../../bson';3import { MongoDBResponse } from '../../cmap/wire_protocol/responses';4import type { Collection } from '../../collection';5import { MONGODB_ERROR_CODES, MongoServerError } from '../../error';6import type { ServerCommandOptions } from '../../sdam/server';7import type { ClientSession } from '../../sessions';8import { type TimeoutContext } from '../../timeout';9import { AbstractOperation } from '../operation';10 11/** @internal */12export class DropSearchIndexOperation extends AbstractOperation<void> {13  override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;14 15  private readonly collection: Collection;16  private readonly name: string;17 18  constructor(collection: Collection, name: string) {19    super();20    this.collection = collection;21    this.name = name;22    this.ns = collection.fullNamespace;23  }24 25  override get commandName() {26    return 'dropSearchIndex' as const;27  }28 29  override buildCommand(_connection: Connection, _session?: ClientSession): Document {30    const namespace = this.collection.fullNamespace;31 32    const command: Document = {33      dropSearchIndex: namespace.collection34    };35 36    if (typeof this.name === 'string') {37      command.name = this.name;38    }39 40    return command;41  }42 43  override handleOk(_response: MongoDBResponse): void {44    // do nothing45  }46 47  override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {48    return { session: this.session, timeoutContext };49  }50 51  override handleError(error: MongoError): void {52    const isNamespaceNotFoundError =53      error instanceof MongoServerError && error.code === MONGODB_ERROR_CODES.NamespaceNotFound;54    if (!isNamespaceNotFoundError) {55      throw error;56    }57  }58}59