2

So, I have one @Document class which has a embedded pojo field which I want it to be unique for the document based on a key in the pojo class. I tried using @CompoundIndex & @Indexed to mark it as unique but it doesn't seem to work.

@Document
public class Project {
    private String id;
    private String name;
    private List<Details> details = new ArrayList<>();
}

public class Details{
    private String key;
    private String description;
}

What I want to achieve is that a project document should have unique details field in it with it's key being unique. But when I have the @CompoundIndexes({ @CompoundIndex(name = "details_key", def = "{'details.key':1}", unique = true) }) on the Project class it doesn't work. Which I thought it should. Or am I wrong somewhere with my understanding. As I am new to this.

Deepak
  • 171
  • 1
  • 12
  • isnt @Id on Details.key enough? – RichieK Jan 30 '19 at 18:22
  • @Deepak - Are you able to solve this issue ? Could you please guide here https://stackoverflow.com/questions/61948943/spring-data-mongo-apply-unique-combination-fields-in-embedded-document – PAA May 22 '20 at 06:41

0 Answers0