@@ -2,18 +2,16 @@ import type { Document } from '../bson';
2
2
import { CursorResponse , ExplainedCursorResponse } from '../cmap/wire_protocol/responses' ;
3
3
import { type AbstractCursorOptions , type CursorTimeoutMode } from '../cursor/abstract_cursor' ;
4
4
import { 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' ;
13
7
import { formatSort , type Sort } from '../sort' ;
14
8
import { type TimeoutContext } from '../timeout' ;
15
9
import { 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' ;
17
15
import { Aspect , defineAspects , type Hint } from './operation' ;
18
16
19
17
/**
@@ -92,7 +90,9 @@ export interface FindOneOptions extends FindOptions {
92
90
}
93
91
94
92
/** @internal */
95
- export class FindOperation extends CommandOperation < CursorResponse > {
93
+ export class FindOperation extends ModernizedCommandOperation < CursorResponse > {
94
+ override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse ;
95
+
96
96
/**
97
97
* @remarks WriteConcern can still be present on the options because
98
98
* we inherit options from the client/db/collection. The
@@ -116,39 +116,32 @@ export class FindOperation extends CommandOperation<CursorResponse> {
116
116
117
117
// special case passing in an ObjectId as a filter
118
118
this . filter = filter != null && filter . _bsontype === 'ObjectId' ? { _id : filter } : filter ;
119
+
120
+ this . SERVER_COMMAND_RESPONSE_TYPE = this . explain ? ExplainedCursorResponse : CursorResponse ;
119
121
}
120
122
121
123
override get commandName ( ) {
122
124
return 'find' as const ;
123
125
}
124
126
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
+ }
133
136
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
+ }
139
142
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 ) ;
152
145
}
153
146
}
154
147
@@ -217,15 +210,6 @@ function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOp
217
210
findCommand . comment = options . comment ;
218
211
}
219
212
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
-
229
213
if ( options . max ) {
230
214
findCommand . max = options . max ;
231
215
}
@@ -263,11 +247,6 @@ function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOp
263
247
if ( typeof options . allowPartialResults === 'boolean' ) {
264
248
findCommand . allowPartialResults = options . allowPartialResults ;
265
249
}
266
-
267
- if ( options . collation ) {
268
- findCommand . collation = options . collation ;
269
- }
270
-
271
250
if ( typeof options . allowDiskUse === 'boolean' ) {
272
251
findCommand . allowDiskUse = options . allowDiskUse ;
273
252
}
0 commit comments