1- import { type Connection } from '..' ;
21import type { Document } from '../bson' ;
32import {
43 MIN_SUPPORTED_QE_SERVER_VERSION ,
54 MIN_SUPPORTED_QE_WIRE_VERSION
65} from '../cmap/wire_protocol/constants' ;
7- import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
86import { Collection } from '../collection' ;
97import type { Db } from '../db' ;
108import { MongoCompatibilityError } from '../error' ;
119import type { PkFactory } from '../mongo_client' ;
10+ import type { Server } from '../sdam/server' ;
1211import type { ClientSession } from '../sessions' ;
1312import { TimeoutContext } from '../timeout' ;
14- import { type CommandOperationOptions , ModernizedCommandOperation } from './command' ;
13+ import { CommandOperation , type CommandOperationOptions } from './command' ;
1514import { executeOperation } from './execute_operation' ;
1615import { CreateIndexesOperation } from './indexes' ;
1716import { Aspect , defineAspects } from './operation' ;
@@ -111,8 +110,7 @@ const INVALID_QE_VERSION =
111110 'Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption.' ;
112111
113112/** @internal */
114- export class CreateCollectionOperation extends ModernizedCommandOperation < Collection > {
115- override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
113+ export class CreateCollectionOperation extends CommandOperation < Collection > {
116114 override options : CreateCollectionOptions ;
117115 db : Db ;
118116 name : string ;
@@ -129,20 +127,25 @@ export class CreateCollectionOperation extends ModernizedCommandOperation<Collec
129127 return 'create' as const ;
130128 }
131129
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 ) ) {
135141 if ( value != null && typeof value !== 'function' && ! ILLEGAL_COMMAND_FIELDS . has ( option ) ) {
136142 cmd [ option ] = value ;
137143 }
138144 }
139- return cmd ;
140- }
141145
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 ) ;
146149 }
147150}
148151
@@ -164,17 +167,23 @@ export async function createCollections<TSchema extends Document>(
164167
165168 if ( encryptedFields ) {
166169 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.
168177 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
171180 ) {
172181 throw new MongoCompatibilityError (
173182 `${ INVALID_QE_VERSION } The minimum server version required is ${ MIN_SUPPORTED_QE_SERVER_VERSION } `
174183 ) ;
175184 }
176185
177- return super . buildCommandDocument ( connection , session ) ;
186+ return super . execute ( server , session , timeoutContext ) ;
178187 }
179188 }
180189
0 commit comments