'How to use MongoAuditting with MongoTemplate?

i'm trying to upsert using MongoTemplate. but auditting does not work.(@CreatedDate, @ModifiedDate fields didn't save) how to enable auditing with MongoTemplate?

i added @EnableMongoAuditting

@Configuration
@EnableMongoAuditing
class MongoConfig

my document class

@Document("sample")
class SampleDocument(
    var title: String
) {
    @MongoId(FieldType.OBJECT_ID)
    var id: String? = null

    @CreatedDate
    var createdAt: LocalDateTime? = null

    @LastModifiedDate
    var lastModifiedAt: LocalDateTime? = null
}

and MongoTemplate query

        mongoTemplate.upsert(
            Query(Criteria.where("title").`is`("Hello")),
            Update().set("title", "Hi"),
            SampleDocument::class.java
        )


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source