@@ -2,18 +2,16 @@ import type { Document } from '../bson';
22import { CursorResponse , ExplainedCursorResponse } from '../cmap/wire_protocol/responses' ;
33import { type AbstractCursorOptions , type CursorTimeoutMode } from '../cursor/abstract_cursor' ;
44import { MongoInvalidArgumentError } from '../error' ;
5- import {
6- decorateWithExplain ,
7- type ExplainOptions ,
8- validateExplainTimeoutOptions
9- } from '../explain' ;
10- import { ReadConcern } from '../read_concern' ;
11- import type { Server } from '../sdam/server' ;
12- import type { ClientSession } from '../sessions' ;
5+ import { type ExplainOptions } from '../explain' ;
6+ import type { ServerCommandOptions } from '../sdam/server' ;
137import { formatSort , type Sort } from '../sort' ;
148import { type TimeoutContext } from '../timeout' ;
159import { type MongoDBNamespace , normalizeHintField } from '../utils' ;
16- import { type CollationOptions , CommandOperation , type CommandOperationOptions } from './command' ;
10+ import {
11+ type CollationOptions ,
12+ type CommandOperationOptions ,
13+ ModernizedCommandOperation
14+ } from './command' ;
1715import { Aspect , defineAspects , type Hint } from './operation' ;
1816
1917/**
@@ -92,7 +90,9 @@ export interface FindOneOptions extends FindOptions {
9290}
9391
9492/** @internal */
95- export class FindOperation extends CommandOperation < CursorResponse > {
93+ export class FindOperation extends ModernizedCommandOperation < CursorResponse > {
94+ override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse ;
95+
9696 /**
9797 * @remarks WriteConcern can still be present on the options because
9898 * we inherit options from the client/db/collection. The
@@ -116,39 +116,32 @@ export class FindOperation extends CommandOperation<CursorResponse> {
116116
117117 // special case passing in an ObjectId as a filter
118118 this . filter = filter != null && filter . _bsontype === 'ObjectId' ? { _id : filter } : filter ;
119+
120+ this . SERVER_COMMAND_RESPONSE_TYPE = this . explain ? ExplainedCursorResponse : CursorResponse ;
119121 }
120122
121123 override get commandName ( ) {
122124 return 'find' as const ;
123125 }
124126
125- override async execute (
126- server : Server ,
127- session : ClientSession | undefined ,
128- timeoutContext : TimeoutContext
129- ) : Promise < CursorResponse > {
130- this . server = server ;
131-
132- const options = this . options ;
127+ override buildOptions ( timeoutContext : TimeoutContext ) : ServerCommandOptions {
128+ return {
129+ ...this . options ,
130+ ...this . bsonOptions ,
131+ documentsReturnedIn : 'firstBatch' ,
132+ session : this . session ,
133+ timeoutContext
134+ } ;
135+ }
133136
134- let findCommand = makeFindCommand ( this . ns , this . filter , options ) ;
135- if ( this . explain ) {
136- validateExplainTimeoutOptions ( this . options , this . explain ) ;
137- findCommand = decorateWithExplain ( findCommand , this . explain ) ;
138- }
137+ override handleOk (
138+ response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE >
139+ ) : CursorResponse {
140+ return response ;
141+ }
139142
140- return await server . command (
141- this . ns ,
142- findCommand ,
143- {
144- ...this . options ,
145- ...this . bsonOptions ,
146- documentsReturnedIn : 'firstBatch' ,
147- session,
148- timeoutContext
149- } ,
150- this . explain ? ExplainedCursorResponse : CursorResponse
151- ) ;
143+ override buildCommandDocument ( ) : Document {
144+ return makeFindCommand ( this . ns , this . filter , this . options ) ;
152145 }
153146}
154147
@@ -217,15 +210,6 @@ function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOp
217210 findCommand . comment = options . comment ;
218211 }
219212
220- if ( typeof options . maxTimeMS === 'number' ) {
221- findCommand . maxTimeMS = options . maxTimeMS ;
222- }
223-
224- const readConcern = ReadConcern . fromOptions ( options ) ;
225- if ( readConcern ) {
226- findCommand . readConcern = readConcern . toJSON ( ) ;
227- }
228-
229213 if ( options . max ) {
230214 findCommand . max = options . max ;
231215 }
@@ -263,11 +247,6 @@ function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOp
263247 if ( typeof options . allowPartialResults === 'boolean' ) {
264248 findCommand . allowPartialResults = options . allowPartialResults ;
265249 }
266-
267- if ( options . collation ) {
268- findCommand . collation = options . collation ;
269- }
270-
271250 if ( typeof options . allowDiskUse === 'boolean' ) {
272251 findCommand . allowDiskUse = options . allowDiskUse ;
273252 }
0 commit comments