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

Dedicated annotations to support Extended Reference Pattern

Open jesmith17 opened this issue 6 months ago • 1 comments

The Extended Reference data modeling pattern in MongoDB is one of the most popular and most powerful, but it's difficult to implement in Spring due to lack of support.

Im recommending creating two new annotations @ExtendedReference and @ExtendedAttribute to support this.

@ExtendedReference would be applied to a embedded object and used to identify that

  • The object needed to be persisted as an embedded document to the parent
  • The @Id or _id of the child object should always be included in the embedded fields
  • Only fields annotated with @ExtendedAttribute or with @Id or @MongoId should be persisted.

Fields with the @ExtendedReference annotation should never be retrieved via $lookup but if needed could be explicitly retrieved and set into the parent object.

This would allow users to take advantage of the extended reference pattern without

  • Creating new custom POJO's to represent the smaller version of the class
  • Having to do extensive custom serialization work
  • Impact any of the existing query operations in the spring-data library.

jesmith17 avatar May 26 '25 17:05 jesmith17

Related to: #4801

christophstrobl avatar May 27 '25 05:05 christophstrobl