spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Extend support around the Extended Reference Pattern via DocumentReferences.

Open christophstrobl opened this issue 1 year ago • 1 comments

Explore if it makes sense to have a different extraction pattern for storing the relation than for the retrieval. Doing so would allow users to build dedicated views on the data for reading operations that require less data and must not resolve the reference.

class Payment {

    String id;

    @DocumentReference(fields = { "id", "name", "birthdate" }, lookup="{ '_id' : ?#{#target.id} }")
    Customer sender;

    PaymentReceiver receiver;

    // ...
}

christophstrobl avatar Oct 02 '24 15:10 christophstrobl

I was just thinking about this, and I think it's a very beneficial pattern to support, but I would probably do it via a dedicated annotation @ExtendedReference instead of @DocumentReference so that you don't confuse the 2.

From a data modeling perspective, you wouldn't want the behavior to flip where sometimes it's the full object and others it's the subset. So I see having the new annotation being a better fit here. I actually created a fork and was going to start working on this.

jesmith17 avatar May 26 '25 13:05 jesmith17