Skip to content

Commit c2f2500

Browse files
authored
CSHARP-4678: Additional collections are created in QE v2 on older servers (#1111)
1 parent 007b3c5 commit c2f2500

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

specifications/client-side-encryption/tests/legacy/fle2v2-CreateCollection-OldServer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,38 @@
5555
"result": {
5656
"errorContains": "Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption."
5757
}
58+
},
59+
{
60+
"name": "assertCollectionNotExists",
61+
"object": "testRunner",
62+
"arguments": {
63+
"database": "default",
64+
"collection": "enxcol_.encryptedCollection.esc"
65+
}
66+
},
67+
{
68+
"name": "assertCollectionNotExists",
69+
"object": "testRunner",
70+
"arguments": {
71+
"database": "default",
72+
"collection": "enxcol_.encryptedCollection.ecc"
73+
}
74+
},
75+
{
76+
"name": "assertCollectionNotExists",
77+
"object": "testRunner",
78+
"arguments": {
79+
"database": "default",
80+
"collection": "enxcol_.encryptedCollection.ecoc"
81+
}
82+
},
83+
{
84+
"name": "assertCollectionNotExists",
85+
"object": "testRunner",
86+
"arguments": {
87+
"database": "default",
88+
"collection": "encryptedCollection"
89+
}
5890
}
5991
]
6092
}

specifications/client-side-encryption/tests/legacy/fle2v2-CreateCollection-OldServer.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,25 @@ tests:
3737
collection: "encryptedCollection"
3838
result:
3939
errorContains: "Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption."
40+
# Assert no collections were created.
41+
- name: assertCollectionNotExists
42+
object: testRunner
43+
arguments:
44+
database: *database_name
45+
collection: &esc_collection_name "enxcol_.encryptedCollection.esc"
46+
# ecc collection is no longer created for QEv2
47+
- name: assertCollectionNotExists
48+
object: testRunner
49+
arguments:
50+
database: *database_name
51+
collection: &ecc_collection_name "enxcol_.encryptedCollection.ecc"
52+
- name: assertCollectionNotExists
53+
object: testRunner
54+
arguments:
55+
database: *database_name
56+
collection: &ecoc_collection_name "enxcol_.encryptedCollection.ecoc"
57+
- name: assertCollectionNotExists
58+
object: testRunner
59+
arguments:
60+
database: *database_name
61+
collection: encryptedCollection

src/MongoDB.Driver.Core/Core/Operations/CreateCollectionOperation.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ internal static IWriteOperation<BsonDocument> CreateEncryptedCreateCollectionOpe
4141
{
4242
var mainOperation = new CreateCollectionOperation(
4343
collectionNamespace,
44-
messageEncoderSettings)
44+
messageEncoderSettings,
45+
encryptedFields != null ? Feature.Csfle2QEv2 : null)
4546
{
4647
EncryptedFields = encryptedFields
4748
};
@@ -62,7 +63,10 @@ internal static IWriteOperation<BsonDocument> CreateEncryptedCreateCollectionOpe
6263
}
6364

6465
CreateCollectionOperation CreateInnerCollectionOperation(string collectionName)
65-
=> new CreateCollectionOperation(new CollectionNamespace(collectionNamespace.DatabaseNamespace.DatabaseName, collectionName), messageEncoderSettings) { ClusteredIndex = new BsonDocument { { "key", new BsonDocument("_id", 1) }, { "unique", true } } };
66+
=> new(new CollectionNamespace(collectionNamespace.DatabaseNamespace.DatabaseName, collectionName), messageEncoderSettings, Feature.Csfle2QEv2)
67+
{
68+
ClusteredIndex = new BsonDocument { { "key", new BsonDocument("_id", 1) }, { "unique", true } }
69+
};
6670
}
6771
#endregion
6872

@@ -89,6 +93,8 @@ CreateCollectionOperation CreateInnerCollectionOperation(string collectionName)
8993
private BsonDocument _validator;
9094
private WriteConcern _writeConcern;
9195

96+
private readonly Feature _supportedFeature;
97+
9298
// constructors
9399
/// <summary>
94100
/// Initializes a new instance of the <see cref="CreateCollectionOperation"/> class.
@@ -109,6 +115,7 @@ private CreateCollectionOperation(
109115
{
110116
_collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace));
111117
_messageEncoderSettings = messageEncoderSettings;
118+
_supportedFeature = supportedFeature;
112119
}
113120

114121
// properties
@@ -455,10 +462,7 @@ private WriteCommandOperation<BsonDocument> CreateOperation(ICoreSessionHandle s
455462

456463
private void EnsureServerIsValid(int maxWireVersion)
457464
{
458-
if (_encryptedFields != null)
459-
{
460-
Feature.Csfle2QEv2.ThrowIfNotSupported(maxWireVersion);
461-
}
465+
_supportedFeature?.ThrowIfNotSupported(maxWireVersion);
462466
}
463467

464468
[Flags]

0 commit comments

Comments
 (0)