Skip to content

Update fails on DocumentReference annotated list #4041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kusamau opened this issue May 4, 2022 · 1 comment
Closed

Update fails on DocumentReference annotated list #4041

kusamau opened this issue May 4, 2022 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@kusamau
Copy link

kusamau commented May 4, 2022

Assume the following class

@Document(collection = "testDocuments")
public class TestDocument {
    @Id
    private UUID id;

    @DocumentReference
    private List<TestDocument> children;
}

then the following test fails

    @Test
    void testDocumentChildrenTest(@Autowired MongoTemplate mongoTemplate) {
        TestDocument parent = new TestDocument();
        parent.setChildren(new ArrayList<>());
        mongoTemplate.save(parent);

        TestDocument child = new TestDocument();
        mongoTemplate.save(child);

        Query query = new Query(Criteria.where("id").is(parent.getId()));

        Update update = new Update();
        update.push("children").each(new Object[]{child});
        var result = mongoTemplate.update(TestDocument.class)
                .matching(query)
                .apply(update)
                .first();

        TestDocument updated = mongoTemplate.findOne(query, TestDocument.class);
        Assertions.assertEquals(1, updated.getChildren().size());
    }

An identical test, replacing @DocumentReference with @DBREF succeeds.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 4, 2022
@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 6, 2022
@christophstrobl christophstrobl self-assigned this May 6, 2022
@christophstrobl
Copy link
Member

Thanks for bringing this up! We'll have a look.

mp911de pushed a commit that referenced this issue Sep 19, 2022
We now make sure to convert references in update operations targeting collection like fields when using eg. the push modifier.

Closes #4041
Original pull request: #4045.
@mp911de mp911de added this to the 3.3.7 (2021.1.7) milestone Sep 19, 2022
mp911de pushed a commit that referenced this issue Sep 19, 2022
We now make sure to convert references in update operations targeting collection like fields when using eg. the push modifier.

Closes #4041
Original pull request: #4045.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants