spring-projects / spring-projects/spring-data-mongodb
Transparently interpret id-values or domain instances for DbRef properties in a query or update as DbRefs [DATAMONGO-855]
Open
@odrotbohm is already working on this.
Since Dec 30, 2020.
in: core
type: enhancement
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Thomas Darimont opened DATAMONGO-855 and commented
We should allow using domain object values or values whose types are compatible to the id property of a document as the value for a DbRef property or collection element in updates.
We should also investigate whether it is possible to use the same semantics in queries.
Sample sample1 = new Sample("1", "A");
Sample sample2 = new Sample("2", "B");
template.save(sample1);
template.save(sample2);
DocumentWithDBRefCollection doc = new DocumentWithDBRefCollection();
doc.id = "1";
doc.dbRefAnnotatedList = Arrays.asList( //
sample1, //
sample2 //
);
template.save(doc);
// use domain object value directly -> transparently interpret as DbRef
Update update = new Update().pull("dbRefAnnotatedList", sample2);
// Use id property value -> transparently interpret as DbRef
Update update = new Update().pull("dbRefAnnotatedList", sample2.id);
}
class DocumentWithDBRefCollection {
@Id public String id;
@org.springframework.data.mongodb.core.mapping.DBRef//
public List<Sample> dbRefAnnotatedList;
}
class Sample{
@Id String id;
String field;
public Sample() {}
public Sample(String id, String field) {
this.id = id;
this.field = field;
}
}
Issue Links:
- DATAMONGO-404 Removing a DBRef using pull does not work
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.