mongodb注解索引不生效问题
2021/8/12 2:06:26
本文主要是介绍mongodb注解索引不生效问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
问题描述:
spring boot + spring data MongoDB 项目中使用@CompoundIndex注解来生成MongoDB索引,但是项目启动后未生效
解决方案:
-
在配置文件中增加:spring.data.mongodb.auto-index-creation: true
-
注意:该注解在第一次生成表的时候生效,如果表已经存在,需要删除表重新生成。
1、新建表时, 通过在实体类上增加@CompoundIndex注解或者实体成员变量上添加@index注解
2、如果需要给已经存在的表建立索引可通过 mongoTemplate.indexOps(xxx.class).ensureIndex(index) ;
这篇关于mongodb注解索引不生效问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26解决google chrome helper 内存占用较高!
- 2024-04-01got an unexpected keyword argument
- 2024-03-30维多利亚的秘密 golang入坑系统
- 2024-03-29mongodb sort by date
- 2024-03-29go swagger
- 2024-03-25mongodb cdc
- 2024-03-25how to use go in vscode
- 2024-03-22mongooseserverselectionerror: connect econnrefused ::1:27017
- 2024-03-21pymongo insert_many
- 2024-03-18projection mongodb