Skip to content

Calling find for reference object when save even ignoreMissing is set to true. #4236

@ball3t

Description

@ball3t

When calling save to an entity with reference. it would call a find before update.
If that's a reference in a list then it causes an N+1 issue.

example:

@Entity(value = "test1", useDiscriminator = false)
public class Test1 {
    @Id
    ObjectId _id;
    String name;
    List<EmbeddedTest2> embeddedTest2s;
...
}

@Entity(useDiscriminator = false)
public static class EmbeddedTest2{
    Integer seq;
    @Reference(idOnly = true, lazy = true, ignoreMissing = true)
    Test2 test2;
...
}

@Entity(value = "test2", useDiscriminator = false)
public class Test2 {
    @Id
    ObjectId _id;
    String name;
...
}

when calling datastore.save(test1). it will call 3 extra time of find "test2" if there are 3 entries.
would it be possible to group it in to 1 call with _id in [...] or just stop calling if ignoreMissing = true?

** Please complete the following information: **
Server Version: 8.0.20
Driver Version: 5.5.1
Morphia Version: 2.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions