Hi,
I just spotted this and am working in this area, so I thought I'd contribute.
As far as I understand the @Id annotation (or a field called 'id' if no annotations is present), maps to the _id attribute in the mongo document.
Therefore, if you provide a value, this will be used.
For example, in using MongoDB for storing my Spring Security user credentials, I have the following:
Code:
@Indexed(unique=true)
private final String email;
@Id
private final UUID publicUuid;
In this case, a different publicUuid will be a different document.
Where I'm stuck though is that I have a test as follows that fails, and I think should pass (i.e. throw the exception):
Code:
@Test(expected=DuplicateKeyException.class)
public void duplicateEmailShouldThrowException() {
SimpleUserDetails user1 = new SimpleUserDetails("unique@emailxyz.info", "password", "Me", "Ape");
user1 = repo.save(user1);
assertNotNull(user1);
SimpleUserDetails user2 = new SimpleUserDetails("unique@emailxyz.info", "diffpassword", "NotMe", "NotApe");
user2 = repo.save(user2);
assertNotNull(user2); // should never get here
}
I think this is a bug/pending feature...