diff --git a/src/index.ts b/src/index.ts index cbe08602526..c41a58fdd4d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -401,7 +401,6 @@ export type { DeleteOptions, DeleteResult, DeleteStatement } from './operations/ export type { DistinctOptions } from './operations/distinct'; export type { DropCollectionOptions, DropDatabaseOptions } from './operations/drop'; export type { EstimatedDocumentCountOptions } from './operations/estimated_document_count'; -export type { EvalOptions } from './operations/eval'; export type { ExecutionResult } from './operations/execute_operation'; export type { FindOptions } from './operations/find'; export type { diff --git a/src/operations/eval.ts b/src/operations/eval.ts deleted file mode 100644 index 3f7699e067c..00000000000 --- a/src/operations/eval.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { Code, type Document } from '../bson'; -import type { Collection } from '../collection'; -import type { Db } from '../db'; -import { MongoServerError } from '../error'; -import { ReadPreference } from '../read_preference'; -import type { Server } from '../sdam/server'; -import type { ClientSession } from '../sessions'; -import { CommandOperation, type CommandOperationOptions } from './command'; - -/** @public */ -export interface EvalOptions extends CommandOperationOptions { - nolock?: boolean; -} - -/** @internal */ -export class EvalOperation extends CommandOperation { - override options: EvalOptions; - code: Code; - parameters?: Document | Document[]; - - constructor( - db: Db | Collection, - code: Code, - parameters?: Document | Document[], - options?: EvalOptions - ) { - super(db, options); - - this.options = options ?? {}; - this.code = code; - this.parameters = parameters; - // force primary read preference - Object.defineProperty(this, 'readPreference', { - value: ReadPreference.primary, - configurable: false, - writable: false - }); - } - - override async execute(server: Server, session: ClientSession | undefined): Promise { - let finalCode = this.code; - let finalParameters: Document[] = []; - - // If not a code object translate to one - if (!(finalCode && (finalCode as unknown as { _bsontype: string })._bsontype === 'Code')) { - finalCode = new Code(finalCode as never); - } - - // Ensure the parameters are correct - if (this.parameters != null && typeof this.parameters !== 'function') { - finalParameters = Array.isArray(this.parameters) ? this.parameters : [this.parameters]; - } - - // Create execution selector - const cmd: Document = { $eval: finalCode, args: finalParameters }; - - // Check if the nolock parameter is passed in - if (this.options.nolock) { - cmd.nolock = this.options.nolock; - } - - // Execute the command - const result = await super.executeCommand(server, session, cmd); - if (result && result.ok === 1) { - return result.retval; - } - - if (result) { - throw new MongoServerError({ message: `eval failed: ${result.errmsg}` }); - } - - return result; - } -} diff --git a/test/mongodb.ts b/test/mongodb.ts index 4a8f21214b8..df85d2cd641 100644 --- a/test/mongodb.ts +++ b/test/mongodb.ts @@ -164,7 +164,6 @@ export * from '../src/operations/delete'; export * from '../src/operations/distinct'; export * from '../src/operations/drop'; export * from '../src/operations/estimated_document_count'; -export * from '../src/operations/eval'; export * from '../src/operations/execute_operation'; export * from '../src/operations/find'; export * from '../src/operations/find_and_modify';