let's say I have the following database entity:
@Document(collection = "users")
public class User {
@Id
private String id;
private String firstname;
private String lastname;
private String email;
}
How can I enforce the field email to be unique? That means MongoDB should check if a user record with this email address already exists when the application tries to save the entity.