spring-boot: 'spring.data.mongodb.auto-index-creation=true' not working
I’ve added as per the documentation the following line to my application.properties:
spring.data.mongodb.auto-index-creation=true
However there is still no index created in my model-class that is annotated with @Document and the field with @Indexed.
If I overwrite autoIndexCreation in Java via:
@Configuration
public class MongoConfig extends AbstractMongoClientConfiguration {
@Override
protected boolean autoIndexCreation() {
return true;
}
}
the index is created. So this method works, but the application.properties entry doesn’t work.
Using Spring Boot 2.5.5
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (4 by maintainers)
More precisely, also for other people, a POJO without
@Document/@Entityannotation gets persisted into the MongoDb and the Collection is also created. Only the annotation with@Documentcauses the index creation.Hi, just to contribute I was with my configs all set, but it was not working, then a did the following change in my
MongoConfig:Before (not creating indexes)
After (creating indexes) - just added
MappingMongoConverter