Skip to content

Commit dacd888

Browse files
Revert "create collection"
This reverts commit bd8fb4b.
1 parent 3918707 commit dacd888

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

src/operations/create_collection.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import { type Connection } from '..';
21
import type { Document } from '../bson';
32
import {
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';
86
import { Collection } from '../collection';
97
import type { Db } from '../db';
108
import { MongoCompatibilityError } from '../error';
119
import type { PkFactory } from '../mongo_client';
10+
import type { Server } from '../sdam/server';
1211
import type { ClientSession } from '../sessions';
1312
import { TimeoutContext } from '../timeout';
14-
import { type CommandOperationOptions, ModernizedCommandOperation } from './command';
13+
import { CommandOperation, type CommandOperationOptions } from './command';
1514
import { executeOperation } from './execute_operation';
1615
import { CreateIndexesOperation } from './indexes';
1716
import { 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

Comments
 (0)