diff options
author | Shreyas Kalyan <shreyas.kalyan@mongodb.com> | 2022-08-17 16:38:16 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-20 09:22:10 +0000 |
commit | 007d0e03ab736568cbd7e89b0d9f681d633f42f7 (patch) | |
tree | c9239ae866521dff84560eb927d8b0d54b58c5f0 /src | |
parent | 5b393e3066017a285646f9d50b91b5b1d9cb5a08 (diff) | |
download | mongo-007d0e03ab736568cbd7e89b0d9f681d633f42f7.tar.gz |
SERVER-68065 Cannot update unindexed field in QE
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/fle_crud.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/mongo/db/fle_crud.cpp b/src/mongo/db/fle_crud.cpp index 783ba424cdf..7a6ed7eb09f 100644 --- a/src/mongo/db/fle_crud.cpp +++ b/src/mongo/db/fle_crud.cpp @@ -841,6 +841,23 @@ write_ops::DeleteCommandReply processDelete(FLEQueryInterface* queryImpl, return deleteReply; } +bool hasIndexedFieldsInSchema(const std::vector<EncryptedField>& fields) { + for (const auto& field : fields) { + if (field.getQueries().has_value()) { + const auto& queries = field.getQueries().get(); + if (stdx::holds_alternative<std::vector<mongo::QueryTypeConfig>>(queries)) { + const auto& vec = stdx::get<0>(queries); + if (!vec.empty()) { + return true; + } + } else { + return true; + } + } + } + return false; +} + /** * Update is the most complicated FLE operation. * It is basically an insert followed by a delete, sort of. @@ -950,8 +967,11 @@ write_ops::UpdateCommandReply processUpdate(FLEQueryInterface* queryImpl, // Fail if we could not find the new document uassert(6371505, "Could not find pre-image document by _id", !newDocument.isEmpty()); - // Check the user did not remove/destroy the __safeContent__ array - FLEClientCrypto::validateTagsArray(newDocument); + if (hasIndexedFieldsInSchema(efc.getFields())) { + // Check the user did not remove/destroy the __safeContent__ array. If there are no + // indexed fields, then there will not be a safeContent array in the document. + FLEClientCrypto::validateTagsArray(newDocument); + } // Step 5 ---- auto originalFields = EDCServerCollection::getEncryptedIndexedFields(originalDocument); @@ -1195,8 +1215,11 @@ write_ops::FindAndModifyCommandReply processFindAndModify( // Fail if we could not find the new document uassert(6371404, "Could not find pre-image document by _id", !newDocument.isEmpty()); - // Check the user did not remove/destroy the __safeContent__ array - FLEClientCrypto::validateTagsArray(newDocument); + if (hasIndexedFieldsInSchema(efc.getFields())) { + // Check the user did not remove/destroy the __safeContent__ array. If there are no + // indexed fields, then there will not be a safeContent array in the document. + FLEClientCrypto::validateTagsArray(newDocument); + } newFields = EDCServerCollection::getEncryptedIndexedFields(newDocument); } |