1
- import type { Document } from '../../bson' ;
1
+ import { BSONType , type Document } from '../../bson' ;
2
+ import { type Connection } from '../../cmap/connection' ;
3
+ import { MongoDBResponse } from '../../cmap/wire_protocol/responses' ;
2
4
import type { Collection } from '../../collection' ;
3
- import type { Server } from '../../sdam/server' ;
5
+ import type { ServerCommandOptions } from '../../sdam/server' ;
4
6
import type { ClientSession } from '../../sessions' ;
5
7
import { type TimeoutContext } from '../../timeout' ;
6
- import { AbstractOperation } from '../operation' ;
8
+ import { ModernizedOperation } from '../operation' ;
7
9
8
10
/**
9
11
* @public
@@ -20,37 +22,37 @@ export interface SearchIndexDescription extends Document {
20
22
}
21
23
22
24
/** @internal */
23
- export class CreateSearchIndexesOperation extends AbstractOperation < string [ ] > {
25
+ export class CreateSearchIndexesOperation extends ModernizedOperation < string [ ] > {
26
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
24
27
private readonly collection : Collection ;
25
28
private readonly descriptions : ReadonlyArray < SearchIndexDescription > ;
26
29
27
30
constructor ( collection : Collection , descriptions : ReadonlyArray < SearchIndexDescription > ) {
28
31
super ( ) ;
29
32
this . collection = collection ;
30
33
this . descriptions = descriptions ;
34
+ this . ns = collection . fullNamespace ;
31
35
}
32
36
33
37
override get commandName ( ) {
34
38
return 'createSearchIndexes' as const ;
35
39
}
36
40
37
- override async execute (
38
- server : Server ,
39
- session : ClientSession | undefined ,
40
- timeoutContext : TimeoutContext
41
- ) : Promise < string [ ] > {
41
+ override buildCommand ( _connection : Connection , _session ?: ClientSession ) : Document {
42
42
const namespace = this . collection . fullNamespace ;
43
- const command = {
43
+ return {
44
44
createSearchIndexes : namespace . collection ,
45
45
indexes : this . descriptions
46
46
} ;
47
+ }
47
48
48
- const res = await server . command ( namespace , command , {
49
- session,
50
- timeoutContext
51
- } ) ;
49
+ override handleOk ( response : MongoDBResponse ) : string [ ] {
50
+ const indexesCreated = response . get ( 'indexesCreated' , BSONType . array , true ) ;
51
+ console . log ( indexesCreated , indexesCreated . toObject ( ) ) ;
52
+ return indexesCreated . toObject ( ) . map ( ( { name } : { name : string } ) => name ) ;
53
+ }
52
54
53
- const indexesCreated : Array < { name : string } > = res ?. indexesCreated ?? [ ] ;
54
- return indexesCreated . map ( ( { name } ) => name ) ;
55
+ override buildOptions ( timeoutContext : TimeoutContext ) : ServerCommandOptions {
56
+ return { session : this . session , timeoutContext } ;
55
57
}
56
58
}
0 commit comments