1
- import { type Connection } from '..' ;
2
1
import type { Document } from '../bson' ;
3
2
import {
4
3
MIN_SUPPORTED_QE_SERVER_VERSION ,
5
4
MIN_SUPPORTED_QE_WIRE_VERSION
6
5
} from '../cmap/wire_protocol/constants' ;
7
- import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
8
6
import { Collection } from '../collection' ;
9
7
import type { Db } from '../db' ;
10
8
import { MongoCompatibilityError } from '../error' ;
11
9
import type { PkFactory } from '../mongo_client' ;
10
+ import type { Server } from '../sdam/server' ;
12
11
import type { ClientSession } from '../sessions' ;
13
12
import { TimeoutContext } from '../timeout' ;
14
- import { type CommandOperationOptions , ModernizedCommandOperation } from './command' ;
13
+ import { CommandOperation , type CommandOperationOptions } from './command' ;
15
14
import { executeOperation } from './execute_operation' ;
16
15
import { CreateIndexesOperation } from './indexes' ;
17
16
import { Aspect , defineAspects } from './operation' ;
@@ -111,8 +110,7 @@ const INVALID_QE_VERSION =
111
110
'Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption.' ;
112
111
113
112
/** @internal */
114
- export class CreateCollectionOperation extends ModernizedCommandOperation < Collection > {
115
- override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
113
+ export class CreateCollectionOperation extends CommandOperation < Collection > {
116
114
override options : CreateCollectionOptions ;
117
115
db : Db ;
118
116
name : string ;
@@ -129,20 +127,25 @@ export class CreateCollectionOperation extends ModernizedCommandOperation<Collec
129
127
return 'create' as const ;
130
128
}
131
129
132
- override buildCommandDocument ( _connection : Connection , _session ?: ClientSession ) : Document {
133
- const cmd : Document = { create : this . name } ;
134
- for ( const [ option , value ] of Object . entries ( this . options ) ) {
130
+ override async execute (
131
+ server : Server ,
132
+ session : ClientSession | undefined ,
133
+ timeoutContext : TimeoutContext
134
+ ) : Promise < Collection > {
135
+ const db = this . db ;
136
+ const name = this . name ;
137
+ const options = this . options ;
138
+
139
+ const cmd : Document = { create : name } ;
140
+ for ( const [ option , value ] of Object . entries ( options ) ) {
135
141
if ( value != null && typeof value !== 'function' && ! ILLEGAL_COMMAND_FIELDS . has ( option ) ) {
136
142
cmd [ option ] = value ;
137
143
}
138
144
}
139
- return cmd ;
140
- }
141
145
142
- override handleOk (
143
- _response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE >
144
- ) : Collection < Document > {
145
- return new Collection ( this . db , this . name , this . options ) ;
146
+ // otherwise just execute the command
147
+ await super . executeCommand ( server , session , cmd , timeoutContext ) ;
148
+ return new Collection ( db , name , options ) ;
146
149
}
147
150
}
148
151
@@ -164,17 +167,23 @@ export async function createCollections<TSchema extends Document>(
164
167
165
168
if ( encryptedFields ) {
166
169
class CreateSupportingFLEv2CollectionOperation extends CreateCollectionOperation {
167
- override buildCommandDocument ( connection : Connection , session ?: ClientSession ) : Document {
170
+ override execute (
171
+ server : Server ,
172
+ session : ClientSession | undefined ,
173
+ timeoutContext : TimeoutContext
174
+ ) : Promise < Collection > {
175
+ // Creating a QE collection required min server of 7.0.0
176
+ // TODO(NODE-5353): Get wire version information from connection.
168
177
if (
169
- ! connection . description . loadBalanced &&
170
- Number ( connection . description . maxWireVersion ) < MIN_SUPPORTED_QE_WIRE_VERSION
178
+ ! server . loadBalanced &&
179
+ server . description . maxWireVersion < MIN_SUPPORTED_QE_WIRE_VERSION
171
180
) {
172
181
throw new MongoCompatibilityError (
173
182
`${ INVALID_QE_VERSION } The minimum server version required is ${ MIN_SUPPORTED_QE_SERVER_VERSION } `
174
183
) ;
175
184
}
176
185
177
- return super . buildCommandDocument ( connection , session ) ;
186
+ return super . execute ( server , session , timeoutContext ) ;
178
187
}
179
188
}
180
189
0 commit comments