"MongoError: Pipeline over an encrypted collection cannot reference additional collections."

I am getting the error “MongoError: Pipeline over an encrypted collection cannot reference additional collections.”
As I can see in my code the errors are coming wherever we have used aggregate like $lookup, $unwind, etc.
So, how to fix this.
Here is the screenshot of that

1 Like

Hi @Great_Manager_Instit,

The produced error you are getting is expected as currently Field Level Encryption fields cannot be use in a foriegn (not-self) collection lookup:

Automatic client-side field level encryption supports the $lookup and $graphLookup only if the from collection matches the collection on which the aggregation runs against (i.e. self-lookup operations).

$lookup and $graphLookup stages that reference a different from collection return an error.

Therefore, the only workaround is to avoid the lookup.

Best regards,
Pavel

We have a large codebase, changing/removing lookup will take time and not looks easy task.
What will be the ideal way to encrypt the data if we have a foreign reference in collections?

Hi, Did you able to fix this issues?