I have an existing database with millions of records where the mobile number is unencrypted. Going forward, we will be encrypting the mobile number of new customers, which we have implemented using setter and getter.
Now here’s the dilemma: let’s say a customer comes after 2 months and we want to check whether his mobile number exists in the database or not. How do I write a single query which performs search using both the encrypted as well as unencrypted value?
One way is using the $or operator, with $or: [{number: encrypted}, {number: unecrypted}]
. But this would involve making changes in queries in multiple places and also make this format a requirement for all future queries involving phone number.
What other ways are there?