Skip to content

Commit 4f7125b

Browse files
authored
CDRIVER-4389 Update FLE 2 Create Collection (#993)
* create state collections with clusteredIndex * drop data collection after state collections
1 parent a63b8ef commit 4f7125b

File tree

3 files changed

+240
-83
lines changed

3 files changed

+240
-83
lines changed

src/libmongoc/src/mongoc/mongoc-collection.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,15 +1065,6 @@ drop_with_opts_with_encryptedFields (mongoc_collection_t *collection,
10651065
bool ok = false;
10661066
const char *name = mongoc_collection_get_name (collection);
10671067

1068-
/* Drop data collection. */
1069-
if (!drop_with_opts (collection, opts, error)) {
1070-
if (error->code == MONGOC_SERVER_ERR_NS_NOT_FOUND) {
1071-
memset (error, 0, sizeof (bson_error_t));
1072-
} else {
1073-
goto fail;
1074-
}
1075-
}
1076-
10771068
/* Drop ESC collection. */
10781069
escName = _mongoc_get_encryptedField_state_collection (
10791070
encryptedFields, name, "esc", error);
@@ -1125,6 +1116,15 @@ drop_with_opts_with_encryptedFields (mongoc_collection_t *collection,
11251116
}
11261117
}
11271118

1119+
/* Drop data collection. */
1120+
if (!drop_with_opts (collection, opts, error)) {
1121+
if (error->code == MONGOC_SERVER_ERR_NS_NOT_FOUND) {
1122+
memset (error, 0, sizeof (bson_error_t));
1123+
} else {
1124+
goto fail;
1125+
}
1126+
}
1127+
11281128
ok = true;
11291129
fail:
11301130
mongoc_collection_destroy (ecocCollection);

src/libmongoc/src/mongoc/mongoc-database.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,15 +1046,27 @@ create_encField_state_collection (mongoc_database_t *database,
10461046
char *state_collection = NULL;
10471047
mongoc_collection_t *collection = NULL;
10481048
bool ok = false;
1049+
bson_t opts = BSON_INITIALIZER;
10491050

10501051
state_collection = _mongoc_get_encryptedField_state_collection (
10511052
encryptedFields, data_collection, state_collection_suffix, error);
10521053
if (!state_collection) {
10531054
goto fail;
10541055
}
10551056

1056-
collection =
1057-
create_collection (database, state_collection, NULL /* opts */, error);
1057+
BCON_APPEND (&opts,
1058+
"clusteredIndex",
1059+
"{",
1060+
"key",
1061+
"{",
1062+
"_id",
1063+
BCON_INT32 (1),
1064+
"}",
1065+
"unique",
1066+
BCON_BOOL (true),
1067+
"}");
1068+
1069+
collection = create_collection (database, state_collection, &opts, error);
10581070
if (collection == NULL) {
10591071
goto fail;
10601072
}
@@ -1063,6 +1075,7 @@ create_encField_state_collection (mongoc_database_t *database,
10631075
fail:
10641076
bson_free (state_collection);
10651077
mongoc_collection_destroy (collection);
1078+
bson_destroy (&opts);
10661079
return ok;
10671080
}
10681081

0 commit comments

Comments
 (0)