In MongoDB client side fields level encryption, When we encrypt records and have multiple data encryption keys(please don't confuse this with master key) in key vault, if we fetch multiple records in a single query, say X records which have 1 field encrypted using Y distinct data encryption keys, I would like to understand how the driver handles fetching of these data encryption keys. I could think of few ways listed below on how it could have been handled, but want to understand exact behaviour to finalise our approach.
- It fetches X records and while decrypting each record, it makes a call to fetch the data encryption key used to encrypt that particular record. So, together, make X db calls to fetch keys.
- Same as above but when it fetches a data encryption key, it stores it in memory to reuse if any other undrecrypted record used the same data encryption key. In this approach, it makes Y db calls to fetch keys.
- It fetches X records and lists down all distinct key identifiers used. Makes a single DB call to fetch all these distinct data encryption keys. In this approach, it makes a single db call to fetch all keys.
- Some other way.
If anyone has idea on how its implemented, please share.
TIA