Skip to content

@EnableMongoAuditing does not play well with MongoRepository#insert #4902

@rfelgent

Description

@rfelgent

Hello,

when pre-populating the @id field before doing a MongoRepository#insert, the auditing functionality will only set the @LastModifiedBy field and ignore the @CreatedBy field.

I expect the MongoRepository#insert method to force a isNew=true flag/strategy throughout the whole persist attempt so that the setting EnableMongoAuditing#modifyOnCreate() default true can kick in.

My current fix is to add a custom EntityCallback ensuring the setting of CreatedBy. This EntityCallback is getting executed after org.springframework.data.mongodb.core.mapping.eventAuditingEntityCallback

Metadata

Metadata

Assignees

Labels

for: stackoverflowA question that's better suited to stackoverflow.com

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions