Mongo审计有选择地工作

我已经启用了mongo审计,@ @CreatedBy@LastModifiedBy的注入是有选择地工作的。 对于某些文档,这两个都不起作用。

 @Document class Category { @Id var id: String? = null @field:Indexed(unique = true) @field:NotEmpty var name: String? = null set(value) { field = value?.trim()?.toLowerCase() } @CreatedDate @JsonProperty(access = JsonProperty.Access.READ_ONLY) var createdDate: Date? = null @LastModifiedDate @JsonProperty(access = JsonProperty.Access.READ_ONLY) var lastModifiedDate: Date? = null @CreatedBy @JsonProperty(access = JsonProperty.Access.READ_ONLY) var createdBy: ObjectId? = null @LastModifiedDate @JsonProperty(access = JsonProperty.Access.READ_ONLY) var lastModifiedBy: ObjectId? = null } 

配置是:

 @Bean fun auditor(): AuditorAware<ObjectId> = AuditorAwareImpl() companion object { class AuditorAwareImpl : AuditorAware<ObjectId> { override fun getCurrentAuditor(): ObjectId? { val authentication = SecurityContextHolder.getContext().authentication if (authentication == null || !authentication.isAuthenticated) return null val principal = authentication.principal if (principal is UserDetailsProvider) { return ObjectId(principal.user.id) } return null } } } 

它使用@EnableMongoAuditing启用。 只有createdBy被存储。 即使修改文档, lastModifiedBy也不存储。 但是当检查AuditorAwareImpl是否被调用时,它工作正常。

对于另一个文档, createdBylastModifiedBy都不存储。 对于另一个文件,这两个都被存储。 所有文档中的时间戳都存储有相同的元数据。

我无法获得这些文件的每一个相同的行为。