Automatic CSFLE Spring boot

I have a working application Spring Boot + Mongo DB. Spring boot 3.1 Java 17 Mongo 7 I have one collection which generates dynamically and all are working fine.

Now, I’m trying to integrate the CSFLE with my existing app. When I did CSFLE POC, it worked well and got the decrypted data and stored the date in encrypted, etc.

After integrating the CSFLE I’m getting the below error.

"Automatic client-side field level encryption supports the $lookup and $graphLookup only if the from collection matches the collection on which the aggregation runs (i.e. self-lookup operations). $lookup and $graphLookup stages that reference a different from collection return an error. " Also this as well when I tried to comment on the generation of the schema using “DB.runCommand(new Document(“collMod”, collStr).append(“validator”, jsonSchemaWrapper(schema)));” as per tutorials suggests.
After comments, I’m getting below error and couldn’t to fix below error
Pipeline over an encrypted collection cannot reference additional collections

Even though there is no encryption field in this collection, still shows the above error. I mean the actual encryption data is present in the different collections.

I have tried the below link for the debugging and reference but no luck. Any suggestion or fix on this issue or any better approach for CSFLE integration on existing applications?

src code ref: GitHub - mongodb-developer/mongodb-java-spring-boot-csfle: This repository contains a Java Spring Boot template to start a MongoDB project with CSFLE. How to Implement Client-Side Field Level Encryption (CSFLE) in Java with Spring Data MongoDB | MongoDB

1 Like

Hi @Ravee_Hinder,

I’m the author of the content you are mentioning. :smile:

So first of all, thanks for reading me! You rock! :muscle:

I found this in the documentation about CSFLE supported opearations:

You cannot perform a $lookup from a CSFLE-enabled MongoClient on unencrypted collections.

So looks like a $lookup pipeline would need to run from a “normal” (understand a non-CSFLE-enabled) MongoDB connection.

In my post, I’m using an ephemeral “normal” MongoDB connection to create the Key Vault and the unique index. Maybe this can help? But I wouldn’t create a new connection each time you are running this pipeline (anti pattern). It worked for me because I just need to do it once at the start (and not at all if they are created manually).

I honestly struggled a lot with the Spring Data configuration when I was writing this post and I don’t think it’s possible to have two MongoDB connections (one normal and one CSFLE-enabled) running in parallel in Spring Data, ready for you to use as you please for each query / pipeline.

Sorry I don’t have a real solution but please let me know if I’m missing something here. There is most likely a solution but let me know if what I said already helps you or not.

Cheers, :clinking_glasses:
Maxime.

1 Like