How to enable auditing for MongoDB via Annotations in Spring How to enable auditing for MongoDB via Annotations in Spring mongodb mongodb

How to enable auditing for MongoDB via Annotations in Spring


Because you are not using configuration via XML, I believe you are using annotations. You own a class like this:

public class MongoConfig extends AbstractMongoConfiguration {...}

Thus, in addition to the annotations you should already have, add: @EnableMongoAuditing

Your configuration class will look like this now:

@Configuration@EnableMongoRepositories(basePackages="...")@EnableMongoAuditingpublic class MongoConfig extends AbstractMongoConfiguration {...}

I hope this helps!


That's all you need. No subclasses or other stuff.

@Configuration@EnableMongoAuditingpublic class AnyCongig {}


You should write a configuration class in which you can connect to MongoDB database using mongoClient by passing db url. and add the anootaion of @EnableMongoAuditing on top of that class.