Skip to content

Failed usage of provided ID value on document insert #4184

Closed
@aburmakov

Description

@aburmakov

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:

@Document(collection = AcmeDocument.COLLECTION_NAME)
public class AcmeDocument implements IdDocument {
    public static final String COLLECTION_NAME = "acme";
    @MongoId
    private String id;
    private String userName;
    public AcmeDocument(String userName) {
        this.id = UUID.randomUUID().toString();
        this.userName = userName;
    }
//...
}

// usage:
AcmeDocument d = new AcmeDocument(userName);
d = acmeRepository.save(d);
log.debug("create.id: {}", d.getId());
Log output: create.id: e43afa9b-06db-4935-a94a-f76578c7af83
But mongoDb document has _Id as generated ObjectId: 6332ca654af6176f2c0c230d

Metadata

Metadata

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions