How to create indexes in MongoDB from Java
You can create indexes in MongoDB from Spring boot application using the following code:
In this code MongoTemplate bean injected by spring as dependency. You also can use MongoOperations
interface.
private final MongoTemplate mongoTemplate;
Function initIndexes() annotated as @PostConstruct will be run by Spring once on beanCreation.