I have the below class as my document.
@Data
@Builder
@Document(collection = "test")
public class TestData {
@Id
private String id;
private String name;
@Indexed(unique = true)
private String hash;
}
Even if I'm using Indexed with unique enabled, I'm able to insert duplicate documents into collection. But if I generate index in mongo shell then it is working.
Is there any way where I can specify unique Index through code only?
error/exceptionyou are getting ? Please add some error/exception trace.unique = true?spring.data.mongodb.auto-index-creation=trueproperty change worked for me stackoverflow.com/questions/53006818/…