I am working on an application using Spring Data MongoDB. I would like to create a compound index on one of my models. I have added a @CompoundIndex annotation at the top li
You need to add the following to application.properties
:
spring.data.mongodb.auto-index-creation=true
or in application.yml
:
spring:
data:
mongodb:
auto-index-creation: true
In this case I would rather go with mongodb createIndex method as it ensures indexes have been created, even if you created them in your app models (Spring boot in this case) it's always better to do a double check and create them manually https://docs.mongodb.com/v3.2/reference/method/db.collection.createIndex/