Partial search on an encrypted field (CSFLE)

Recently I came across an error while trying to implement partial search on an encrypted(Automatic CSFLE) filed.

For example, I have an email address “sample@mail.com” in the database. When the user searches for “samp”, I have to run a query to fetch the “sample@mail.com” from the database. Also, the Client Side Field Level Encryption is enabled in the email field. When I try to achieve this using $regex, I’m getting the following error

“MongoError: Invalid match expression operator on encrypted field ‘name’”
I have been googling for a while but still not see any good solution. Are there any solutions to this?.

Hi @master_user,

Welcome to MongoDB community.

Consider the limitations of FLE encryption, there is no server side to achieve this regex ability for encrypted fields:
https://docs.mongodb.com/manual/reference/security-client-side-query-aggregation-support/#supported-query-operators

I suggest to. Consider another schema design for your searches, for example store the initial part of the email in an uncrypted field (egm sample) and search on it.

Best
Pavel

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.