-
Notifications
You must be signed in to change notification settings - Fork 9
Indexes auto creation problem
Kais OMRI edited this page May 27, 2020
·
1 revision
- Starting with spring-data 2.2.X and RelMongo v3.2.0 the activation of the indexes auto creation is deprecated (ie: using @Indexed, @CompoundIndexes...), it is recommanded to write your own script which create indexes manually to insure a safe run of spring based applications and other applications that access the database.
But if you still need to create indexes automatically through spring, you need to provide little more configuration in order for RelMongo to work properly: => provide a MappingMongoConverter bean that used a new provided RelMongoMappingContext see example below :
RelMongoMappingContext mappingContext = new RelMongoMappingContext();
mappingContext.setAutoIndexCreation(true); // default false (recommanded)
// set the mappingContext in the MappingConverter
MappingMongoConverter mappingMongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(simpleMongoDbFactory), mappingContext);
mappingMongoConverter.setCustomConversions(customConversions);
mappingMongoConverter.afterPropertiesSet();
// now you can use your MappingMongoConverter directly in a mongoTemplate or provide it to spring as a bean
© Copyright Kais OMRI under the Apache License 2.0