-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Failed usage of provided ID value on document insert #4184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I might be missing something but I cannot reproduce the issue. class AcmeDocument {
@MongoId
private String id;
private String userName;
public MyOddIdDocument(String userName) {
this.id = UUID.randomUUID().toString();
this.userName = userName;
}
}
template.dropCollection(AcmeDocument.class);
AcmeDocument source = new AcmeDocument("one");
template.save(source);
org.bson.Document dbDoc = collection.find().limit(1).cursor().next());
assertThat(dbDoc).isNotNull();
assertThat(dbDoc.get("_id")).isEqualTo(source.id);
AcmeDocument loaded = template.findOne(query(where("id").is(source.id)), AcmeDocument.class);
assertThat(loaded).isEqualTo(source);
assertThat(loaded.id).isInstanceOf(String.class); Please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem. |
@christophstrobl Hey, please take a look at referenced issue spring-projects/spring-boot#32635. It has a reproducible example and focuses on |
save also creates the wrong ID in spring boot 2.7.4: https://github.com/pcornelissen/springboot-mongo-bug @mp911de As you have worked on that, is there an ETA for a new release? |
Self-generated ID cannot be insert into mongo collection. System-generated ObjectID.get() is used instead of self-generatd.
Looks like problem appears after commit: 8ee33b2 ("Generate and convert id on insert if explicitly defined.", 2022-05-19)
Sample code:
The text was updated successfully, but these errors were encountered: