spring-projects / spring-projects/spring-data-mongodb
Map collection and fields for `$lookup`/`$graphLookup` aggregation stage against domain type
Open
@christophstrobl is already working on this.
Since Jun 7, 2023.
type: enhancement
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Working on a legacy code base, we've got lots of code that builds up aggregations including lookups, so we want to lookup the collection name for a class.
We've got an implementation that I'm guessing was at some point copied from mongo, but doesn't seem up to date and digging through code can assume it was copied from
BasicMongoPersistentEntity
public BasicMongoPersistentEntity(TypeInformation<T> typeInformation) {
super(typeInformation, MongoPersistentPropertyComparator.INSTANCE);
Class<?> rawType = typeInformation.getType();
String fallback = MongoCollectionUtils.getPreferredCollectionName(rawType);
if (this.isAnnotationPresent(Document.class)) {
Document document = this.getRequiredAnnotation(Document.class);
this.collection = StringUtils.hasText(document.collection()) ? document.collection() : fallback;
this.language = StringUtils.hasText(document.language()) ? document.language() : "";
this.expression = detectExpression(document.collection());
this.collation = document.collation();
this.collationExpression = detectExpression(document.collation());
} else {
this.collection = fallback;
this.language = "";
this.expression = null;
this.collation = null;
this.collationExpression = null;
}
Is there any reason this isn't exposed as a static method call so anyone can resolve class name to collection name consistently with how mongo does it?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.