spring-projects / spring-projects/spring-data-mongodb

Allow `DbRefResolver` to resolve bulk entities

Open
#4,820 0 comments 0 reactions 1 assignee View on GitHub

@christophstrobl is already working on this.

Since Oct 28, 2024.

status: waiting-for-triage
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

It is relatively easy to override DbRefResolver.resolveDbRef() to return a single cached entity object
But if you want to handle the case where the property is a collection of DbRefs it is impossible. The method has no access to the list of DbRef values.
While you can override the bulkFetch() method this returns a list of Document objects - not useful if your cache contains the deserialized objects.
Currently the only solution is to extensively override the MappingMongoConverter. Since many of the methods in this class are private or package scope this requires a lot of code which will likely break with future updates.

Please add a new bulkResolveDbRef() method to DbRefResolver and call this from either MongoMappingConverter.bulkReadAndConvertDBRefs() (before bulkReadRefs()) or MappingMongoConverter.readAssociation() and passing in the full list of DbRefs to give the DbRefResolver a chance to retrieve cached entities.
Ideally DbRefResolver could return a partial list or map DbRef -> Object and MongoMappingConverter could fetch the remaining.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.