@CompoundIndex not working in Spring Data MongoDB

前端 未结 2 1781
闹比i
闹比i 2021-01-04 18:21

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

相关标签:
2条回答
  • 2021-01-04 19:02

    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
    
    0 讨论(0)
  • 2021-01-04 19:06

    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/

    0 讨论(0)
提交回复
热议问题