Skip to content

Commit 6845069

Browse files
authored
chore(NODE-4246): update FLE2 collection management (#3251)
1 parent 52eb62b commit 6845069

File tree

4 files changed

+817
-516
lines changed

4 files changed

+817
-516
lines changed

src/operations/create_collection.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ export class CreateCollectionOperation extends CommandOperation<Collection> {
133133
const ecocCollection = encryptedFields.ecocCollection ?? `enxcol_.${name}.ecoc`;
134134

135135
for (const collectionName of [escCollection, eccCollection, ecocCollection]) {
136-
const createOp = new CreateCollectionOperation(db, collectionName);
136+
const createOp = new CreateCollectionOperation(db, collectionName, {
137+
clusteredIndex: {
138+
key: { _id: 1 },
139+
unique: true
140+
}
141+
});
137142
await createOp.executeWithoutEncryptedFieldsCheck(server, session);
138143
}
139144

src/operations/drop.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,6 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
5151
encryptedFields = listCollectionsResult?.[0]?.options?.encryptedFields;
5252
}
5353

54-
let result;
55-
let errorForMainOperation;
56-
try {
57-
result = await this.executeWithoutEncryptedFieldsCheck(server, session);
58-
} catch (err) {
59-
if (
60-
!encryptedFields ||
61-
!(err instanceof MongoServerError) ||
62-
err.code !== MONGODB_ERROR_CODES.NamespaceNotFound
63-
) {
64-
throw err;
65-
}
66-
// Save a possible NamespaceNotFound error for later
67-
// in the encryptedFields case, so that the auxilliary
68-
// collections will still be dropped.
69-
errorForMainOperation = err;
70-
}
71-
7254
if (encryptedFields) {
7355
const escCollection = encryptedFields.escCollection || `enxcol_.${name}.esc`;
7456
const eccCollection = encryptedFields.eccCollection || `enxcol_.${name}.ecc`;
@@ -88,13 +70,9 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
8870
}
8971
}
9072
}
91-
92-
if (errorForMainOperation) {
93-
throw errorForMainOperation;
94-
}
9573
}
9674

97-
return result;
75+
return await this.executeWithoutEncryptedFieldsCheck(server, session);
9876
})().then(
9977
result => callback(undefined, result),
10078
err => callback(err)

0 commit comments

Comments
 (0)